Skip to content

Commit

Permalink
refactor: use set_attributes for set ac mode
Browse files Browse the repository at this point in the history
- update terncy to 0.3.9
- get rid of hack set_attributes method
  • Loading branch information
rxwen committed Nov 6, 2023
1 parent 556ef55 commit 8cefe7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
14 changes: 9 additions & 5 deletions custom_components/terncy/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,23 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_RUNNING, 0)
else:
await self.api.set_attribute(self.eid, K_AC_RUNNING, 1)
attrs = [{"attr": K_AC_RUNNING, "value": 1}]
if hvac_mode == HVACMode.COOL:
attrs.append({"attr": K_AC_MODE, "value": 1})
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 1)
await self.api.set_attributes(self.eid, attrs)
elif hvac_mode == HVACMode.DRY:
attrs.append({"attr": K_AC_MODE, "value": 2})
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 2)
await self.api.set_attributes(self.eid, attrs)
elif hvac_mode == HVACMode.FAN_ONLY:
attrs.append({"attr": K_AC_MODE, "value": 4})
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 4)
await self.api.set_attributes(self.eid, attrs)
elif hvac_mode == HVACMode.HEAT:
attrs.append({"attr": K_AC_MODE, "value": 8})
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 8)
await self.api.set_attributes(self.eid, attrs)
else:
_LOGGER.warning("Unsupported hvac_mode: %s", hvac_mode)
self.async_write_ha_state()
Expand Down
30 changes: 5 additions & 25 deletions custom_components/terncy/core/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,31 +203,11 @@ async def set_attribute(self, eid: str, attr: str, value, method=0):
self.update_listeners(eid, [{"attr": attr, "value": value}])
return ret

async def set_attributes(self, eid: str, attrs: list[AttrValue]):
"""hack"""
api = self.api
if api._connection is None:
_LOGGER.info(f"no connection with {api.dev_id}")
return None
req_id = _next_req_id()
data = {
"reqId": req_id,
"intent": "execute",
"entities": [
{
"id": eid,
"attributes": [
{
"attr": av["attr"],
"value": av["value"],
"method": 0,
}
for av in attrs
],
}
],
}
await api._connection.send(json.dumps(data))
async def set_attributes(self, eid: str, attrs: list[AttrValue], method=0):
_LOGGER.info(eid)
ret = await self.api.set_attributes(eid, attrs, method)
self.update_listeners(eid, attrs)
return ret

# region Event handlers

Expand Down
4 changes: 2 additions & 2 deletions custom_components/terncy/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"integration_type": "hub",
"iot_class": "local_push",
"issue_tracker": "https://github.com/rxwen/homeassistant-terncy-component/issues",
"requirements": ["terncy==0.3.5","websockets>=10.3","zeroconf>=0.28.8"],
"version": "1.0.33",
"requirements": ["terncy==0.3.9","websockets>=10.3","zeroconf>=0.28.8"],
"version": "1.0.35",
"zeroconf": [
{"type":"_websocket._tcp.local.","name":"box-*"}
]
Expand Down

0 comments on commit 8cefe7e

Please sign in to comment.