From f123f0bb77f085dc95f1cdc161572c28484e64a4 Mon Sep 17 00:00:00 2001 From: AndreaTomatis Date: Sat, 20 Apr 2024 16:27:28 +0200 Subject: [PATCH] Improved code. --- custom_components/vesync/__init__.py | 3 ++- custom_components/vesync/binary_sensor.py | 6 +++--- custom_components/vesync/button.py | 3 ++- custom_components/vesync/fan.py | 7 ++++--- custom_components/vesync/sensor.py | 6 +++--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/custom_components/vesync/__init__.py b/custom_components/vesync/__init__.py index cdcfcd4..41bb19f 100644 --- a/custom_components/vesync/__init__.py +++ b/custom_components/vesync/__init__.py @@ -1,4 +1,5 @@ """VeSync integration.""" + from datetime import timedelta import logging @@ -69,7 +70,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b try: await hass.async_add_executor_job(manager.update) except Exception as err: - raise UpdateFailed(f"Update failed: {err}") + raise UpdateFailed(f"Update failed: {err}") from err coordinator = DataUpdateCoordinator( hass, diff --git a/custom_components/vesync/binary_sensor.py b/custom_components/vesync/binary_sensor.py index a9dbd8f..38e3eb4 100644 --- a/custom_components/vesync/binary_sensor.py +++ b/custom_components/vesync/binary_sensor.py @@ -1,4 +1,5 @@ """Support for power & energy sensors for VeSync outlets.""" + import logging from homeassistant.components.binary_sensor import BinarySensorEntity @@ -46,7 +47,7 @@ def _setup_entities(devices, async_add_entities, coordinator): for dev in devices: if hasattr(dev, "fryer_status"): for stype in BINARY_SENSOR_TYPES_AIRFRYER.values(): - entities.append( + entities.append( # noqa: PERF401 VeSyncairfryerSensor( dev, coordinator, @@ -88,8 +89,7 @@ class VeSyncairfryerSensor(VeSyncBaseEntity, BinarySensorEntity): @property def is_on(self) -> bool: """Return a value indicating whether the Humidifier's water tank is lifted.""" - value = getattr(self.airfryer, self.stype[0], None) - return value + return getattr(self.airfryer, self.stype[0], None) # return self.smarthumidifier.details["water_tank_lifted"] @property diff --git a/custom_components/vesync/button.py b/custom_components/vesync/button.py index 8109629..c02cbfc 100644 --- a/custom_components/vesync/button.py +++ b/custom_components/vesync/button.py @@ -1,4 +1,5 @@ """Support for VeSync button.""" + import logging from homeassistant.components.button import ButtonEntity @@ -55,7 +56,7 @@ def _setup_entities(devices, async_add_entities, coordinator): for dev in devices: if hasattr(dev, "cook_set_temp"): for stype in SENSOR_TYPES_CS158.values(): - entities.append( + entities.append( # noqa: PERF401 VeSyncairfryerButton( dev, coordinator, diff --git a/custom_components/vesync/fan.py b/custom_components/vesync/fan.py index 6b3e736..25de507 100644 --- a/custom_components/vesync/fan.py +++ b/custom_components/vesync/fan.py @@ -1,4 +1,5 @@ """Support for VeSync fans.""" + import math from homeassistant.components.fan import FanEntity, FanEntityFeature @@ -165,9 +166,9 @@ class VeSyncFanHA(VeSyncDevice, FanEntity): def turn_on( self, - speed: str = None, - percentage: int = None, - preset_mode: str = None, + # speed: str | None = None, + percentage: int | None = None, + preset_mode: str | None = None, **kwargs, ) -> None: """Turn the device on.""" diff --git a/custom_components/vesync/sensor.py b/custom_components/vesync/sensor.py index 9a4cd09..4ce8198 100644 --- a/custom_components/vesync/sensor.py +++ b/custom_components/vesync/sensor.py @@ -1,4 +1,5 @@ """Support for power & energy sensors for VeSync outlets.""" + import logging from homeassistant.components.sensor import ( @@ -57,7 +58,7 @@ def _setup_entities(devices, async_add_entities, coordinator): for dev in devices: if hasattr(dev, "fryer_status"): for stype in SENSOR_TYPES_AIRFRYER.values(): - entities.append( + entities.append( # noqa: PERF401 VeSyncairfryerSensor( dev, coordinator, @@ -111,8 +112,7 @@ class VeSyncairfryerSensor(VeSyncBaseEntity, SensorEntity): @property def native_value(self): """Return the value.""" - value = getattr(self.airfryer, self.stype[5], None) - return value + return getattr(self.airfryer, self.stype[5], None) @property def native_unit_of_measurement(self):