Skip to content

Commit

Permalink
Even more linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LaStrada committed Jan 1, 2025
1 parent 459c403 commit 345d74b
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions airthings_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from bleak import BleakClient, BleakError
from bleak.backends.device import BLEDevice
from bleak_retry_connector import BleakClientWithServiceCache, establish_connection
from bleak.backends.service import BleakGATTService

from airthings_ble.wave_enhance.request import (
WaveEnhanceRequest,
Expand Down Expand Up @@ -662,7 +663,13 @@ async def _get_service_characteristics(
else:
await self._wave_sensor_data(client, device, sensors, service)

async def _wave_sensor_data(self, client, device, sensors, service):
async def _wave_sensor_data(
self,
client: BleakClient,
device: AirthingsDevice,
sensors: dict[str, str | float | None],
service: BleakGATTService,
) -> None:
for characteristic in service.characteristics:
uuid = characteristic.uuid
uuid_str = str(uuid)
Expand Down Expand Up @@ -724,7 +731,14 @@ async def _wave_sensor_data(self, client, device, sensors, service):
# Stop notification handler
await client.stop_notify(characteristic)

async def _wave_enhance_sensor_data(self, client, device, sensors, service) -> None:
async def _wave_enhance_sensor_data(
self,
client: BleakClient,
device: AirthingsDevice,
sensors: dict[str, str | float | None],
service: BleakGATTService,
) -> None:
"""Get sensor data from the Wave Enhance."""
if self.device_info.model.need_firmware_upgrade(self.device_info.sw_version):
self.logger.warning(
"The firmware for this Wave Enhance is not up to date, "
Expand All @@ -744,6 +758,10 @@ async def _wave_enhance_sensor_data(self, client, device, sensors, service) -> N
atom_write = service.get_characteristic(COMMAND_UUID_WAVE_ENHANCE)
atom_notify = service.get_characteristic(COMMAND_UUID_WAVE_ENHANCE_NOTIFY)

if atom_write is None or atom_notify is None:
self.logger.error("Missing characteristics for Wave Enhance")
raise ValueError("Missing characteristics for Wave Enhance")

# Set up the notification handlers
await client.start_notify(atom_notify, command_data_receiver)

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

if (hum := command_sensor_data.get("HUM")) is not None:
new_values["humidity"] = hum / 100.0
new_values["humidity"] = float(hum) / 100.0

if (temperature := command_sensor_data.get("TMP")) is not None:
# Temperature reported as kelvin
new_values["temperature"] = round(temperature / 100.0 - 273.15, 2)
new_values["temperature"] = round(
float(temperature) / 100.0 - 273.15, 2
)

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

if (pressure := command_sensor_data.get("PRS")) is not None:
new_values["pressure"] = pressure / (64 * 100)
new_values["pressure"] = float(pressure) / (64 * 100)

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

Expand Down

0 comments on commit 345d74b

Please sign in to comment.