MadPatrick / somfy

Tahoma/Conexoon plugin for IO blinds, this plugin require internet connexion and a Somfy account
GNU General Public License v3.0
14 stars 3 forks source link

Updated beta plugin 4.2.20 is not working #57

Closed Rik60 closed 3 weeks ago

Rik60 commented 8 months ago

Describe the bug To solve issue #56 the plugin has been updated, but the plugin is not starting. The master version is starting, the beta version not. There are some problems with the modified files utils.py and plugin.py. There are missing tab or spaces.

In Utils.py lines 61 to 77 has to be modified from:

def filter_states(Data): """filters relevant state data from a device setup API reply""" logging.debug("start filter states") filtered_states = list() deviceURL = "" deviceClass = ""

for device in Data: stateList = list() deviceURL = device["deviceURL"] deviceClass = device["definition"]["uiClass"] if not "states" in device: continue for state in device["states"]: if state["name"] in stateSet: stateList.append(state) if len(stateList)>0: stateToAdd = {"deviceURL":deviceURL, "deviceStates":stateList, "deviceClass":deviceClass, "name":"DeviceState"} filtered_states.append(stateToAdd) logging.debug("Device state: "+str(filtered_states)) return filtered_states

Change the file into:

def filter_states(Data): """filters relevant state data from a device setup API reply""" logging.debug("start filter states") filtered_states = list() deviceURL = "" deviceClass = ""

for device in Data:
    stateList = list()
    deviceURL = device["deviceURL"]
    deviceClass = device["definition"]["uiClass"]
    if not "states" in device:
        continue
    for state in device["states"]:
        if state["name"] in stateSet:
            stateList.append(state)
    if len(stateList)>0:
        stateToAdd = {"deviceURL":deviceURL, 
            "deviceStates":stateList,
            "deviceClass":deviceClass,
            "name":"DeviceState"}
        filtered_states.append(stateToAdd)
    logging.debug("Device state: "+str(filtered_states))
return filtered_states

File plugin.py modify lines 363 and 381 to 386 (showing 361 to 387):

        if (dataset["deviceURL"].startswith("io://")):
            dev = dataset["deviceURL"]
    deviceClassTrig = dataset["deviceClass"] 
            level = 0
            status_num = 0
            status = None
            nValue = 0
            sValue = "0"

            states = dataset["deviceStates"]
            if not (dataset["name"] == "DeviceStateChangedEvent" or dataset["name"] == "DeviceState"):
                logging.debug("update_devices_status: dataset['name'] != DeviceStateChangedEvent: "+str(dataset["name"])+": breaking out")
                continue #dataset does not contain correct event, skip to next dataset

            for state in states:
                status_num = 0
                lumstatus_l = False

                if ((state["name"] == "core:ClosureState") or (state["name"] == "core:DeploymentState")):
                    if (deviceClassTrig == "Awning"):
                    level = int(state["value"]) #Don't invert open/close percentage for an Awning
                    status_num = 1
                else:
                    level = int(state["value"])
                    level = 100 - level #invert open/close percentage
                    status_num = 1

Modify the lines 361 and 381 to 386 (showing 361 to 387) in:

        if (dataset["deviceURL"].startswith("io://")):
            dev = dataset["deviceURL"]
            deviceClassTrig = dataset["deviceClass"] 
            level = 0
            status_num = 0
            status = None
            nValue = 0
            sValue = "0"

            states = dataset["deviceStates"]
            if not (dataset["name"] == "DeviceStateChangedEvent" or dataset["name"] == "DeviceState"):
                logging.debug("update_devices_status: dataset['name'] != DeviceStateChangedEvent: "+str(dataset["name"])+": breaking out")
                continue #dataset does not contain correct event, skip to next dataset

            for state in states:
                status_num = 0
                lumstatus_l = False

                if ((state["name"] == "core:ClosureState") or (state["name"] == "core:DeploymentState")):
                    if (deviceClassTrig == "Awning"):
                        level = int(state["value"]) #Don't invert open/close percentage for an Awning
                        status_num = 1
                    else:
                        level = int(state["value"])
                        level = 100 - level #invert open/close percentage
                        status_num = 1
MadPatrick commented 7 months ago

can you try again.