Skip to content

Commit

Permalink
change dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj committed Nov 6, 2024
1 parent 5762bef commit 4e6565f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions pyacaia_async/acaiascale.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@


@dataclass(kw_only=True)
class AcaiaData:
"""Data class for Acaia scale data."""
class AcaiaDeviceState:
"""Data class for acaia scale info data."""

battery_level: int
weight: float
units: UnitMass


class AcaiaScale:
"""Representation of an Acaia scale."""
"""Representation of an acaia scale."""

_default_char_id = DEFAULT_CHAR_ID
_notify_char_id = NOTIFY_CHAR_ID
Expand Down Expand Up @@ -81,7 +80,8 @@ def __init__(
self._timestamp_last_command: float | None = None
self.last_disconnect_time: float | None = None

self._data = AcaiaData(battery_level=0, weight=0.0, units=UnitMass.GRAMS)
self._device_state: AcaiaDeviceState | None = None
self._weight: float | None = None

# queue
self._queue: asyncio.Queue = asyncio.Queue()
Expand All @@ -101,9 +101,9 @@ def mac(self) -> str:
return self._client.address.upper()

@property
def data(self) -> AcaiaData:
"""Return the data of the scale."""
return self._data
def device_state(self) -> AcaiaDeviceState | None:
"""Return the device info of the scale."""
return self._device_state

@classmethod
async def create(
Expand Down Expand Up @@ -402,14 +402,15 @@ async def on_bluetooth_data_received(
msg = decode(data)[0]

if isinstance(msg, Settings):
self._data.battery_level = msg.battery
self._data.units = UnitMass(msg.units)
self._device_state = AcaiaDeviceState(
battery_level=msg.battery, units=UnitMass(msg.units)
)
_LOGGER.debug(
"Got battery level %s, units %s", str(msg.battery), str(msg.units)
)

elif isinstance(msg, Message):
self._data.weight = msg.value or 0
self._weight = msg.value
if msg.timer_running is not None:
self.timer_running = msg.timer_running
_LOGGER.debug("Got weight %s", str(msg.value))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pyacaia_async",
version="0.0.12b2",
version="0.0.12b3",
description="An async implementation of PyAcaia",
long_description=readme,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 4e6565f

Please sign in to comment.