States vs Properties
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
States vs Properties
One more question? How would I do the reverse of trackName = indigo.devices[DEVICEID].states["track"]? In other words, how would I assign a new state value to a plugin device? I tried "musicPlayer.pluginProps["playertype"]=SQplayer0name" but I do not see the revised playertype value in the device states on the devices page.
- jay (support)
- Site Admin
- Posts: 19232
- Joined: Wed Mar 19, 2008 11:52 am
- Location: Austin, Texas
- Contact:
Re: Basic iTunes plugin questions
State values can only be set by the plugin itself. Plugins will supply actions to modify states as is necessary for the operation of the plugin. Also, only the plugin that "owns" the device can add/remove states.
In terms of iTunes, you can't specify a specific track to start playing, mainly because that involves playlists (from the API perspective you always have to specify a playlist when you want to start playing a specific track, even if the playlist is "Library"). The plugin doesn't currently support playlists (it is on the feature request list though).
In terms of iTunes, you can't specify a specific track to start playing, mainly because that involves playlists (from the API perspective you always have to specify a playlist when you want to start playing a specific track, even if the playlist is "Library"). The plugin doesn't currently support playlists (it is on the feature request list though).
- jay (support)
- Site Admin
- Posts: 19232
- Joined: Wed Mar 19, 2008 11:52 am
- Location: Austin, Texas
- Contact:
Re: Basic iTunes plugin questions
By the way, from your post it looks like what you want to do is add a state to iTunes that you would manage. What would you be using that state for? Just trying to get a bit more color on what you want to do.
Re: Basic iTunes plugin questions
I should have move the heading - sorry. I have modified and really beefed up the plugin for the grand concerto (music player) and have it interfacing with iTunes and 2 Squeezeboxes to flash the title and other information about the track playing on the concerto keypads. Still tweaking it and hoping to get in touch with Swancoat (who wrote the initial plugin) before trying to share.
One thing I decided to do was to try to move the Squeezebox interaction to its own plugin and have the grand concerto plugin reference it (as it does with iTunes). I have created the Squeezebox device in my plugin and have properties for (1) player ID and (2) 9 preset values for playlists or XM Radio stations. It also has states for (1) play/pause/stop; (2) volume; (3) on/off; (4) track; (5) artist; (6) playlist; (7) duration; (8) Squeezebox ID, (9) Squeezebox Name etc.
I have a startup python script which reads each player id property (for now 0, 1 or 2) and sets the state for the Squeezebox ID and Squeezebox Name:
I am then trying to use the "playerid: state to lookup the other state information in the concurrent loop:
The problem I am having is that the state playerid is stored for the device, but my attempt to capture this field fails because my script language is for a property and not a state. I can either make playerid a property (in which case I need to modify my script on the tope to store the property value and not the state value, or else I can fix the second script to reference the state "playerid" and not the property "playerid". That is where I am stuck now at least. And yet, this thread should probably be moved out of iTunes and into Squeezebox or something else (sorry).
One thing I decided to do was to try to move the Squeezebox interaction to its own plugin and have the grand concerto plugin reference it (as it does with iTunes). I have created the Squeezebox device in my plugin and have properties for (1) player ID and (2) 9 preset values for playlists or XM Radio stations. It also has states for (1) play/pause/stop; (2) volume; (3) on/off; (4) track; (5) artist; (6) playlist; (7) duration; (8) Squeezebox ID, (9) Squeezebox Name etc.
I have a startup python script which reads each player id property (for now 0, 1 or 2) and sets the state for the Squeezebox ID and Squeezebox Name:
Code: Select all
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.pluginPrefs[u"sqHOST"],int(self.pluginPrefs[u"sqPORT"])))
for musicPlayer in indigo.devices.iter("com.perrygershon.indigoplugin.squeezebox"):
playernum=musicPlayer.pluginProps["playerselect"]
s.send("player name "+playernum+" ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")
SQplayername=self.sqprocess(data,"player name "+playernum+" ")
s.send("player id "+playernum+" ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")
SQplayerid=self.sqprocess(data,"player id "+playernum+" ")
musicPlayer.updateStateOnServer("playerid", value=SQplayerid)
musicPlayer.updateStateOnServer("playertype", value=SQplayername)
s.close()
Code: Select all
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.pluginPrefs[u"sqHOST"],int(self.pluginPrefs[u"sqPORT"])))
for musicPlayer in indigo.devices.iter("com.perrygershon.indigoplugin.squeezebox"):
SQplayerid=musicPlayer.pluginProps["playerid"]
self.debugLog("playerid:"+SQplayerid+".")
s.send(SQplayerid+" artist ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")+" "
data=self.sqprocess(data,SQplayerid+" artist ")
self.debugLog("artist:"+data)
musicPlayer.updateStateOnServer("artist", value=data)
- jay (support)
- Site Admin
- Posts: 19232
- Joined: Wed Mar 19, 2008 11:52 am
- Location: Austin, Texas
- Contact:
Re: States vs Properties
Moved to a new topic.
Not sure I'm following you because I can't see everything (which are states, which are properties, where the code segments are, etc). There are two sections of the docs that will probably shed some light for you: About Plugin Properties and About Custom Device States.
If those don't answer your questions, then I'm afraid you'll have to get a lot more specific (explain the devices involved, their respective states and properties, any interaction between them, and where the various script parts are located).
Not sure I'm following you because I can't see everything (which are states, which are properties, where the code segments are, etc). There are two sections of the docs that will probably shed some light for you: About Plugin Properties and About Custom Device States.
If those don't answer your questions, then I'm afraid you'll have to get a lot more specific (explain the devices involved, their respective states and properties, any interaction between them, and where the various script parts are located).
Re: States vs Properties
So here are specifics:
Device: Squeezebox (id:musicPlayer)
Properties: playerselect (0/1/2), Button1 (text), Button2 (text),Button3...Button9
States: "playerid", "playertype", "onOffState", "Volume","PlayPauseStop","track","artist","playlist","path","duration","remaining"
State playerid is obtained based on the value of property playerselect.
This works OK. The I try to obtain values for the other states based on the value of state playerid. What I want to do is set SQplayerid (variable in my script) equal to the value of state:playerid. I am not doing this correctly. After that, I query my device I set the other state values. That code works fine:
I am stalled out at: SQplayerid= [value of state playerid]. Don't know how to say that in python.
Device: Squeezebox (id:musicPlayer)
Properties: playerselect (0/1/2), Button1 (text), Button2 (text),Button3...Button9
States: "playerid", "playertype", "onOffState", "Volume","PlayPauseStop","track","artist","playlist","path","duration","remaining"
State playerid is obtained based on the value of property playerselect.
Code: Select all
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.pluginPrefs[u"sqHOST"],int(self.pluginPrefs[u"sqPORT"])))
for musicPlayer in indigo.devices.iter("com.perrygershon.indigoplugin.squeezebox"):
playernum=musicPlayer.pluginProps["playerselect"]
s.send("player name "+playernum+" ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")
SQplayername=self.sqprocess(data,"player name "+playernum+" ")
s.send("player id "+playernum+" ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")
SQplayerid=self.sqprocess(data,"player id "+playernum+" ")
musicPlayer.updateStateOnServer("playerid", value=SQplayerid)
musicPlayer.updateStateOnServer("playertype", value=SQplayername)
s.close()
Code: Select all
s.send(SQplayerid+" artist ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")+" "
data=self.sqprocess(data,SQplayerid+" artist ")
self.debugLog("artist:"+data)
musicPlayer.updateStateOnServer("artist", value=data)
s.send(SQplayerid+" track ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")+" "
data=self.sqprocess(data,SQplayerid+" track ")
self.debugLog("track:"+data)
musicPlayer.updateStateOnServer("track", value=data)
s.send(SQplayerid+" duration ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")+" "
data=self.sqprocess(data,SQplayerid+" duration ")
self.debugLog("duration:"+data)
musicPlayer.updateStateOnServer("duration", value=data)
s.send(SQplayerid+" time ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")+" "
data=self.sqprocess(data,SQplayerid+" time ")
self.debugLog("time:"+data)
musicPlayer.updateStateOnServer("remaining", value=data)
s.send(SQplayerid+" playlist name ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")+" "
data=self.sqprocess(data,SQplayerid+" playlist name ")
self.debugLog("Playlist name:"+data)
musicPlayer.updateStateOnServer("playlist", value=data)
s.send(SQplayerid+" path ?\r\n")
data = s.recv(1024)
data=data.rstrip("\r\n")+" "
data=self.sqprocess(data,SQplayerid+" path ")
self.debugLog("Path:"+data)
musicPlayer.updateStateOnServer("path", value=data)
Re: States vs Properties
OK, I got it: SQplayerid=musicPlayer.states["playerid"]