device address - more basic than basic question

Posted on
Thu Jan 12, 2017 1:58 pm
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

device address - more basic than basic question

I'm looking for some help if I may. I've searched for around 3 hours and I think my question is so basic, the answer isn't out there!

I have hacked together my first plugin, and have it working. Its for Panasonic TV control. When I say hacked, I compare it to a home made kart, with bent perambulator wheels and six inch nails waiting to rip a limb open - but it works and I'm almost ready to post it save for one point.....

I have my main plugin.py module and a number of other modules, and need to get the device address (user entered IP) into the following line of code which is located in the non-plugin.py module. I've sorted out creating the device and entering the ip address, and presume its stored globally somewhere?

Code: Select all
location = "http://192.168.1.252:55000/nrc/ddd.xml"


Please can someone assist with solving this first and last question please, then you can all really have a good laugh at the code - it's a hack like never before, as I know, no python.

Cheers


Mat

Late 2018 mini 10.14

Posted on
Thu Jan 12, 2017 3:44 pm
jay (support) offline
Site Admin
User avatar
Posts: 18216
Joined: Mar 19, 2008
Location: Austin, Texas

Re: device address - more basic than basic question

So, just so I understand: your plugin presents a device. When the user creates an instance of the device, the device's config dialog collects the IP address. If that's true, then the IP address is available in the device's properties dictionary:

Code: Select all
dev = indigo.devices[YOURDEVICEIDHERE]
location = "http://%s/nrc/ddd.xml" % dev.pluginProps["IPADDRESSFIELDKEY"]


The last line gets the ip address/port number from the device's properties. In your Device.xml, you have a ConfigUI with an text field in there to collect the IP:PORT. The id of that field is what you substitute for IPADDRESSFIELDKEY.

Check out the Plugin Properties section of the Device class docs. All values defined in the ConfigUI for a device (in Devices.xml) are automatically added to the devices's pluginProps.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jan 12, 2017 4:09 pm
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: device address - more basic than basic question

Thanks jay. Yes. To all of you questions, except the port as that's fixed by Panasonic I believe, but I should be able to figure it from there.

Thanks for the response, I'll try it tomorrow - just going to bed.

I'll read the link again, now I know where to read.

Thanks again

Late 2018 mini 10.14

Posted on
Fri Jan 13, 2017 4:36 pm
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: device address - more basic than basic question

ok, i've been on this all day, and have read loads and looked at countless examples. I think I am now code blind. Fed up now...any help greatly appreciated.

I have this action in my plugin.py module

Code: Select all
   def mute(self, instruction, devId):
      dev=indigo.devices[devId]
      from pyviera import VieraFinder
      if __name__ == '__main__':
         vf = VieraFinder()
         tv = vf.get_viera()
          tv.mute()


and another module ...pyviera

Code: Select all
import socket
import indigo

from urllib2 import urlopen

from parsing import parse_discovery_response, parse_description

IFACE = '0.0.0.0'
SSDP_MCAST_ADDR = '239.255.255.250'
SSDP_PORT = 1900

class VieraFinder(object):

    def __init__(self):
        desc_url = self.discover()
        desc = urlopen(desc_url).read()
        self.viera = parse_description(desc, desc_url)

    def get_viera(self):
        return self.viera

    def discover(self):
        header = 'M-SEARCH * HTTP/1.1'
        fields = (
            ('ST', 'urn:panasonic-com:device:p00RemoteController:1'),
            ('MX', '1'),
            ('MAN', '"ssdp:discover"'),
            ('HOST', '239.255.255.250:1900'),
        )

        p = self._make_packet(header, fields)
        dev=indigo.devices["MatsOfficeTVControl"]
        location = "http://%s:55000/nrc/ddd.xml" % dev.pluginProps["address"]
        return location

    def _make_packet(self, header, fields):
        return '\r\n'.join([header] + [': '.join(pair) for pair in fields]) + '\r\n'


The code works as is, but i need to change the dev=indigo.devices["MatsOfficeTVControl"] to dev=indigo.devices[devId] but this throws an error as the object has no attribute. I understand that, as I've not introduced it to the second module. And there I am stuck!

I didnt write the second module and whilst I can see generally whats going on and I have it working as above, it needs work with multiple devices.

What is frustrating me is how to get the dev.Id into the second module and where. Just getting frustrated....

Thanks for any help, or perhaps an answer at this time of night.

Late 2018 mini 10.14

Posted on
Fri Jan 13, 2017 5:19 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: device address - more basic than basic question

In the first code segment, change to this:

Code: Select all
         vf = VieraFinder(dev)


In the second segment:

Code: Select all
    def __init__(self, dev):
        desc_url = self.discover(dev)
        desc = urlopen(desc_url).read()
        self.viera = parse_description(desc, desc_url)


Code: Select all
    def discover(self, dev):


And remove this line:

Code: Select all
        dev=indigo.devices["MatsOfficeTVControl"]


Note: I personally would NEVER actually put code like this into production, but if you're happy with cut and paste coding, go for it.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Jan 13, 2017 5:31 pm
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: device address - more basic than basic question

Thanks for the help.

I had tried that unfortunately, and it throws the following error....

Traceback (most recent call last):
File "plugin.py", line 45, in mute
File "/Library/Application Support/Perceptive Automation/Indigo 7/Plugins/Panasonic Network Remote.indigoPlugin/Contents/Server Plugin/pyviera.py", line 11, in __init__
TypeError: discover() takes exactly 1 argument (2 given)

I would love to not cut and paste code, but its all a learning curve, and I'm close to the bottom. On the plus side I have learnt loads today and will continue tomorrow.

Late 2018 mini 10.14

Posted on
Fri Jan 13, 2017 5:34 pm
FlyingDiver offline
User avatar
Posts: 7213
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: device address - more basic than basic question

mat wrote:
Thanks for the help.

I had tried that unfortunately, and it throws the following error....

Traceback (most recent call last):
File "plugin.py", line 45, in mute
File "/Library/Application Support/Perceptive Automation/Indigo 7/Plugins/Panasonic Network Remote.indigoPlugin/Contents/Server Plugin/pyviera.py", line 11, in __init__
TypeError: discover() takes exactly 1 argument (2 given)

I would love to not cut and paste code, but its all a learning curve, and I'm close to the bottom. On the plus side I have learnt loads today and will continue tomorrow.


My bad. I left out a change needed in my original post, then edited to fix it. You still need this change:

Code: Select all
    def discover(self, dev):

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Fri Jan 13, 2017 5:36 pm
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: device address - more basic than basic question

Perfect, thank you and have a great weekend.

:D

Late 2018 mini 10.14

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests