|
Page 1 of 1
|
[ 11 posts ] |
|
Non-standard characters, e.g. degree symbol?
| Author |
Message |
|
yergeyj
Joined: Dec 29, 2004 Posts: 239
|
 Non-standard characters, e.g. degree symbol?
Can non-standard unicode characters be included in device states? I've tried various ways to include a degree symbol, including using the unicode equivalent \u00B0, but none of them seem to work? A few examples: - Code: Select all
newTemp = "75°F"
newTemp = u"75\u00B0F"
I've always been able to include the degree symbol in Indigo string variables, but haven't figured it out in python / Indigo state variables? [NOTE: Not only don't they work, but when I tried to include in Device.xml it caused the Indigo client to crash!!] Jim
|
| Fri Sep 09, 2011 9:58 pm |
|
 |
|
jay (support)
Site Admin
Joined: Mar 19, 2008 Posts: 6651 Location: Austin, Texas
|
 Re: Non-standard characters, e.g. degree symbol?
We'll take a look at it. Python 2.x isn't exactly great at Unicode support.
_________________ Jay (Indigo Support)
|
| Fri Sep 09, 2011 11:12 pm |
|
 |
|
matt (support)
Site Admin
Joined: Jan 27, 2003 Posts: 11689 Location: Texas
|
 Re: Non-standard characters, e.g. degree symbol?
Actually it should work fine. I just tried it and didn't have any problem setting a device state to a unicode string. The problem, which we need to document better, is that value as used in the XML here: - Code: Select all
<List> <Option value="fahrenKey">F, any XML encoded unicode string in here should be okay</Option> <Option value="celsiusKey">C, any XML encoded unicode string in here should be okay</Option> </List>
is not really a device state value string. It is the unique value key to identify that particular list item. Instead of value we probably should have called it id, valueKey, or valueID. So the values you use there needs to follow the same rules as id's: - id's can contain letters, numbers, and other ASCII characters
- id's cannot start with a number or punctuation character
- id's cannot start with the letters xml (or XML, or Xml, etc)
- id's cannot contain spaces
Note, however, that the value is not the same as an actual device state values. Those can contain any unicode characters. Depending on what you are doing, when you calculate the device state string you will probably have to convert between the value in the XML (that is the valueKey) and the actual unicode string state you want to set.
_________________
|
| Sat Sep 10, 2011 2:48 pm |
|
 |
|
yergeyj
Joined: Dec 29, 2004 Posts: 239
|
 Re: Non-standard characters, e.g. degree symbol?
Yeah - I finally sorted this out. One caution - while non-standard characters seem to be OK to pass along to a state, e.g. using an Action to include "°F", python coding requires the use of unicode to enter non-standard characters, e.g. u"\u00B0" for the degree symbol. Also, if a non-standard character is entered for a state value, it will show up properly in the Indigo UI, but if you try to access these values from a Terminal session, e.g. using the following to see elements of your device ... - Code: Select all
dev = indigo.devices[devId] print dev
... you will generate an error : "UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 33: ordinal not in range(128)" Jim
|
| Wed Sep 14, 2011 8:50 pm |
|
 |
|
matt (support)
Site Admin
Joined: Jan 27, 2003 Posts: 11689 Location: Texas
|
 Re: Non-standard characters, e.g. degree symbol?
yergeyj wrote:you will generate an error : "UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 33: ordinal not in range(128)"
I'm not positive it will fix this particular problem, but inside the Terminal settings go to the Advanced panel and make sure the Character Encoding combox box near the bottom is set to Unicode (UTF-8).
_________________
|
| Wed Sep 14, 2011 9:03 pm |
|
 |
|
jay (support)
Site Admin
Joined: Mar 19, 2008 Posts: 6651 Location: Austin, Texas
|
 Re: Non-standard characters, e.g. degree symbol?
The python print statement expects python str objects - everything else it tries to convert (like many built-ins). Unfortunately, many nonstandard chars don't get converted by the default encoder. Try this with the unicode string: - Code: Select all
print u.encode('ascii', 'ignore')
It'll ignore anything it can't encode properly and it won't throw. I use it in several plugins for a variety of reasons.
_________________ Jay (Indigo Support)
|
| Wed Sep 14, 2011 10:02 pm |
|
 |
|
ckeyes888
Joined: Nov 26, 2009 Posts: 923 Location: Kalispell, MT
|
 Re: Non-standard characters, e.g. degree symbol?
I'd like to add the degree symbol ° to a temperature variable whenever it changes. Been searching around but am still unclear what the command may be.
Any ideas?
Thanks,
Carl
|
| Tue Jul 03, 2012 1:31 pm |
|
 |
|
jay (support)
Site Admin
Joined: Mar 19, 2008 Posts: 6651 Location: Austin, Texas
|
 Re: Non-standard characters, e.g. degree symbol?
What's changing the variable? That's what needs to be modified to add it - but not knowing what's changing it keeps me from answering the question... 
_________________ Jay (Indigo Support)
|
| Tue Jul 03, 2012 1:45 pm |
|
 |
|
ckeyes888
Joined: Nov 26, 2009 Posts: 923 Location: Kalispell, MT
|
 Re: Non-standard characters, e.g. degree symbol?
I think I found it using the (ASCII character 188) command.
Thanks,
Carl
|
| Tue Jul 03, 2012 2:00 pm |
|
 |
|
yergeyj
Joined: Dec 29, 2004 Posts: 239
|
 Re: Non-standard characters, e.g. degree symbol?
jay (support) wrote:What's changing the variable? That's what needs to be modified to add it - but not knowing what's changing it keeps me from answering the question... 
Carl, I think what Jay means is where in Indigo are you using the symbol. If it's just part of a variable, just enter the symbol (on a Mac it's just a option-shift-8 to place a degree symbol as text) into variable value. The original reason for this post has to do with processing degree symbols, and related higher-level ASCII charters, using python, which is not as simple. Hope that helps, Jim
|
| Thu Jul 05, 2012 8:05 am |
|
 |
|
ckeyes888
Joined: Nov 26, 2009 Posts: 923 Location: Kalispell, MT
|
 Re: Non-standard characters, e.g. degree symbol?
It was used just in a variable. I use VNC to do most of my programming from my iPad which for some reason doesn't seem to allow me to enter the degree character.
Got it all working.
Thanks,
Carl
|
| Thu Jul 05, 2012 3:54 pm |
|
|
|
Page 1 of 1
|
[ 11 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|