Skip to content

Commit

Permalink
Merge pull request mariusmotea#95 from n3PH1lim/master
Browse files Browse the repository at this point in the history
Support for older Tasmota Versions
  • Loading branch information
mariusmotea authored Feb 24, 2019
2 parents afa1f11 + b535b82 commit d5a2c4a
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions BridgeEmulator/protocols/tasmota.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def discover(bridge_config, new_lights):
if response.status_code == 200:
device_data = json.loads(response.text)
#logging.debug(pretty_json(device_data))
if ("StatusSTS" in device_data) and ("Color" in device_data["StatusSTS"]):
if ("StatusSTS" in device_data):

logging.debug("tasmota: " + ip + " is a Tasmota device ")
logging.debug ("tasmota: Hostname: " + device_data["StatusNET"]["Hostname"] )
Expand Down Expand Up @@ -60,13 +60,6 @@ def discover(bridge_config, new_lights):










def set_light(address, light, data):
logging.debug("tasmota: <set_light> invoked! IP=" + address["ip"])

Expand Down Expand Up @@ -97,10 +90,22 @@ def get_light_state(address, light):
logging.debug("tasmota: <get_light_state> invoked!")
data = sendRequest ("http://" + address["ip"] + "/cm?cmnd=Status%2011")
light_data = json.loads(data)["StatusSTS"]
rgb = light_data["Color"].split(",")
logging.debug("tasmota: <get_light_state>: red " + str(rgb[0]) + " green " + str(rgb[1]) + " blue " + str(rgb[2]) )
state = {}
state['on'] = True if light_data["POWER"] == "ON" else False
state["xy"] = convert_rgb_xy(int(rgb[0],16), int(rgb[1],16), int(rgb[2],16))
state["colormode"] = "xy"

if 'POWER'in light_data:
state['on'] = True if light_data["POWER"] == "ON" else False
elif 'POWER1'in light_data:
state['on'] = True if light_data["POWER1"] == "ON" else False

if 'Color' not in light_data:
if state['on'] == True:
state["xy"] = convert_rgb_xy(255,255,255)
state["bri"] = int(255)
state["colormode"] = "xy"
else:
rgb = light_data["Color"].split(",")
logging.debug("tasmota: <get_light_state>: red " + str(rgb[0]) + " green " + str(rgb[1]) + " blue " + str(rgb[2]) )
state['on'] = True if light_data["POWER1"] == "ON" else False
state["xy"] = convert_rgb_xy(int(rgb[0],16), int(rgb[1],16), int(rgb[2],16))
state["colormode"] = "xy"
return state

0 comments on commit d5a2c4a

Please sign in to comment.