Slight plugin modification or major undertaking?!?

Posted on
Wed Dec 07, 2016 9:31 pm
chobo offline
Posts: 126
Joined: Dec 08, 2013
Location: USA

Slight plugin modification or major undertaking?!?

All,

I've been attempting to add an action to the great Ecobee 3 plugin (https://github.com/jdhorne/indigo-ecobee-plugin), but as a Python/Indigo Plugin Dev. novice, I'm getting nowhere. Here's what I'm attempting to do:

Simply call the resume_program function in the pyecobee library via an Indigo action (in actions.xml). This function doesn't currently exist in the plugin.py file, but it does exist in pyecobee/__init__.py file in the plugin bundle:

Code: Select all
def resume_program(self, index, resume_all="false"):
        ''' Resume currently scheduled program '''
        url = 'https://api.ecobee.com/1/thermostat'
        header = {'Content-Type': 'application/json;charset=UTF-8',
                  'Authorization': 'Bearer ' + self.access_token}
        params = {'format': 'json'}
        body = ('{"functions":[{"type":"resumeProgram","params":{"resumeAll"'
                ':"' + resume_all + '"}}],"selection":{"selectionType"'
                ':"thermostats","selectionMatch":"'
                + self.thermostats[index]['identifier'] + '"}}')
        request = requests.post(url, headers=header, params=params, data=body)
        if request.status_code == requests.codes.ok:
            self._invalidate_cache()
            return request
        else:
            log.warning("Error connecting to Ecobee while attempting to resume"
                  " program.  Refreshing tokens...")
            self.refresh_tokens()

This seems like it should be simple, but I get the error "plugin does not define method resume_program" every time! Where am I going wrong as I attempt to define resume_program in plugin.py and call it from actions.xml? Help!

Thanks in advance!
chobo997

Posted on
Thu Dec 08, 2016 4:23 am
DaveL17 offline
User avatar
Posts: 6743
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Slight plugin modification or major undertaking?!?

If I understand your question, it should be pretty easy. The callback in Actions.xml must be defined in plugin.py.

In Actions.xml:
Code: Select all
<CallbackMethod>resumeProgram</CallbackMethod>

in plugin.py:
Code: Select all
import pyecobee

def resumeProgram(self, valuesDict):
    index = some_value
    resume_all = 'true' or 'false'  # Presumably the options are true/false. There may be others.
    return self.pyecobee.resume_program(index, resume_all)

The resume_all attribute is optional (presumed to be 'false' if missing). pyecobee will return some information from the request if it's successful.

As far as I know, it's not possible to go directly from Actions.xml --> pyecobee.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest