Skip to content

Commit 345d74b

Browse files
committed
Even more linter fixes
1 parent 459c403 commit 345d74b

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

airthings_ble/parser.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from bleak import BleakClient, BleakError
1818
from bleak.backends.device import BLEDevice
1919
from bleak_retry_connector import BleakClientWithServiceCache, establish_connection
20+
from bleak.backends.service import BleakGATTService
2021

2122
from airthings_ble.wave_enhance.request import (
2223
WaveEnhanceRequest,
@@ -662,7 +663,13 @@ async def _get_service_characteristics(
662663
else:
663664
await self._wave_sensor_data(client, device, sensors, service)
664665

665-
async def _wave_sensor_data(self, client, device, sensors, service):
666+
async def _wave_sensor_data(
667+
self,
668+
client: BleakClient,
669+
device: AirthingsDevice,
670+
sensors: dict[str, str | float | None],
671+
service: BleakGATTService,
672+
) -> None:
666673
for characteristic in service.characteristics:
667674
uuid = characteristic.uuid
668675
uuid_str = str(uuid)
@@ -724,7 +731,14 @@ async def _wave_sensor_data(self, client, device, sensors, service):
724731
# Stop notification handler
725732
await client.stop_notify(characteristic)
726733

727-
async def _wave_enhance_sensor_data(self, client, device, sensors, service) -> None:
734+
async def _wave_enhance_sensor_data(
735+
self,
736+
client: BleakClient,
737+
device: AirthingsDevice,
738+
sensors: dict[str, str | float | None],
739+
service: BleakGATTService,
740+
) -> None:
741+
"""Get sensor data from the Wave Enhance."""
728742
if self.device_info.model.need_firmware_upgrade(self.device_info.sw_version):
729743
self.logger.warning(
730744
"The firmware for this Wave Enhance is not up to date, "
@@ -744,6 +758,10 @@ async def _wave_enhance_sensor_data(self, client, device, sensors, service) -> N
744758
atom_write = service.get_characteristic(COMMAND_UUID_WAVE_ENHANCE)
745759
atom_notify = service.get_characteristic(COMMAND_UUID_WAVE_ENHANCE_NOTIFY)
746760

761+
if atom_write is None or atom_notify is None:
762+
self.logger.error("Missing characteristics for Wave Enhance")
763+
raise ValueError("Missing characteristics for Wave Enhance")
764+
747765
# Set up the notification handlers
748766
await client.start_notify(atom_notify, command_data_receiver)
749767

@@ -776,17 +794,19 @@ async def _wave_enhance_sensor_data(self, client, device, sensors, service) -> N
776794
new_values["voc"] = voc
777795

778796
if (hum := command_sensor_data.get("HUM")) is not None:
779-
new_values["humidity"] = hum / 100.0
797+
new_values["humidity"] = float(hum) / 100.0
780798

781799
if (temperature := command_sensor_data.get("TMP")) is not None:
782800
# Temperature reported as kelvin
783-
new_values["temperature"] = round(temperature / 100.0 - 273.15, 2)
801+
new_values["temperature"] = round(
802+
float(temperature) / 100.0 - 273.15, 2
803+
)
784804

785805
if (noise := command_sensor_data.get("NOI")) is not None:
786806
new_values["noise"] = noise
787807

788808
if (pressure := command_sensor_data.get("PRS")) is not None:
789-
new_values["pressure"] = pressure / (64 * 100)
809+
new_values["pressure"] = float(pressure) / (64 * 100)
790810

791811
self.logger.debug("Sensor values: %s", new_values)
792812

0 commit comments

Comments
 (0)