power: fix type/checking formatting for Hue device

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-07-17 06:38:38 -04:00
parent 4d803ec9e5
commit bcb7a55996
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 15 additions and 13 deletions

View File

@ -1296,23 +1296,25 @@ class HueDevice(HTTPDevice):
async def _send_power_request(self, state: str) -> str: async def _send_power_request(self, state: str) -> str:
new_state = True if state == "on" else False new_state = True if state == "on" else False
url = f"http://{self.addr}/api" \ url = (
f"/{self.user}/lights" \ f"http://{self.addr}/api/{self.user}/lights/{self.device_id}/state"
f"/{self.device_id}/state" )
url = self.client.escape_url(url) url = self.client.escape_url(url)
ret = await self.client.request("PUT", ret = await self.client.request("PUT", url, body={"on": new_state})
url, resp = cast(List[Dict[str, Dict[str, Any]]], ret)
body={"on": new_state}) return (
return "on" if \ "on" if resp[0]["success"][f"/lights/{self.device_id}/state/on"]
ret.json()[0].get("success")[f"/lights/{self.device_id}/state/on"] \
else "off" else "off"
)
async def _send_status_request(self) -> str: async def _send_status_request(self) -> str:
ret = await self.client.request("GET", url = (
f"http://{self.addr}/api/" f"http://{self.addr}/api/{self.user}/lights/{self.device_id}"
f"{self.user}/lights/" )
f"{self.device_id}") url = self.client.escape_url(url)
return "on" if ret.json().get("state")["on"] else "off" ret = await self.client.request("GET", url)
resp = cast(Dict[str, Dict[str, Any]], ret)
return "on" if resp["state"]["on"] else "off"
# The power component has multiple configuration sections # The power component has multiple configuration sections