Skip to content

Commit

Permalink
Handle signed integers in handle_cmd_heartbeat properly (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbock authored Dec 5, 2024
1 parent f60a8c6 commit ec609f2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion toshiba_ac/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import asyncio
import logging
import struct
import typing as t
from dataclasses import dataclass

Expand Down Expand Up @@ -129,7 +130,8 @@ async def handle_cmd_fcu_from_ac(self, payload: dict[str, JSONSerializable]) ->
await self.state_changed()

async def handle_cmd_heartbeat(self, payload: dict[str, t.Any]) -> None:
hb_data = {k: int(v, base=16) for k, v in payload.items()}
# Use signed conversion for temperatures, unsigned otherwise.
hb_data = {k: struct.unpack("b" if "Temp" in k else "B", bytes.fromhex(v))[0] for k, v in payload.items()}
logger.debug(f"[{self.name}] AC heartbeat from AMQP: {hb_data}")

if self.fcu_state.update_from_hbt(hb_data):
Expand Down

0 comments on commit ec609f2

Please sign in to comment.