power.py: fix issue with single relay tasmota

add a check and handle consequently in case tasmota device is only one relay and would return a power value when asked a power1 value

Signed-off-by:  Arnaud Schaer <arnaud.schaer@wanadoo.fr>
This commit is contained in:
Arnaud Schaer 2021-04-02 13:45:45 +02:00 committed by Eric Callahan
parent c36f989c52
commit 85b1b44e20
1 changed files with 14 additions and 2 deletions

View File

@ -455,7 +455,13 @@ class Tasmota(PowerDevice):
async def refresh_status(self):
try:
res = await self._send_tasmota_command("info")
try:
state = res[f"POWER{self.output_id}"].lower()
except KeyError as e:
if self.output_id == 1 :
state = res[f"POWER"].lower()
else:
raise KeyError(e)
except Exception:
self.state = "error"
msg = f"Error Refeshing Device Status: {self.name}"
@ -466,7 +472,13 @@ class Tasmota(PowerDevice):
async def set_power(self, state):
try:
res = await self._send_tasmota_command(state)
try:
state = res[f"POWER{self.output_id}"].lower()
except KeyError as e:
if self.output_id == 1 :
state = res[f"POWER"].lower()
else:
raise KeyError(e)
except Exception:
self.state = "error"
msg = f"Error Setting Device Status: {self.name} to {state}"