From 4e6565f68824679c111437c24b3c066289e69446 Mon Sep 17 00:00:00 2001 From: Josef Zweck <24647999+zweckj@users.noreply.github.com> Date: Wed, 6 Nov 2024 20:13:00 +0100 Subject: [PATCH] change dataclass --- pyacaia_async/acaiascale.py | 23 ++++++++++++----------- setup.py | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pyacaia_async/acaiascale.py b/pyacaia_async/acaiascale.py index 7c682a8..fa6d58f 100644 --- a/pyacaia_async/acaiascale.py +++ b/pyacaia_async/acaiascale.py @@ -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 @@ -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() @@ -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( @@ -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)) diff --git a/setup.py b/setup.py index b3b6df4..d6b88dd 100644 --- a/setup.py +++ b/setup.py @@ -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",