diff --git a/custom_components/xiaomi_gateway3/__init__.py b/custom_components/xiaomi_gateway3/__init__.py index 1107b1c3..9577157f 100644 --- a/custom_components/xiaomi_gateway3/__init__.py +++ b/custom_components/xiaomi_gateway3/__init__.py @@ -4,8 +4,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant -from homeassistant.helpers import config_validation as cv -from homeassistant.helpers import device_registry +from homeassistant.helpers import config_validation as cv, device_registry from homeassistant.helpers.device_registry import DeviceEntry from homeassistant.helpers.typing import ConfigType diff --git a/custom_components/xiaomi_gateway3/climate.py b/custom_components/xiaomi_gateway3/climate.py index 87c755e1..b828cd8c 100644 --- a/custom_components/xiaomi_gateway3/climate.py +++ b/custom_components/xiaomi_gateway3/climate.py @@ -1,12 +1,12 @@ from homeassistant.components.climate import ( ClimateEntity, ClimateEntityFeature, + FAN_AUTO, + FAN_HIGH, FAN_LOW, FAN_MEDIUM, - FAN_HIGH, - FAN_AUTO, - HVACMode, HVACAction, + HVACMode, ) from homeassistant.const import PRECISION_WHOLE, UnitOfTemperature diff --git a/custom_components/xiaomi_gateway3/config_flow.py b/custom_components/xiaomi_gateway3/config_flow.py index 4780eea7..e2de8583 100644 --- a/custom_components/xiaomi_gateway3/config_flow.py +++ b/custom_components/xiaomi_gateway3/config_flow.py @@ -1,11 +1,11 @@ import homeassistant.helpers.config_validation as cv import voluptuous as vol -from homeassistant.config_entries import ConfigFlow, ConfigEntry, OptionsFlow +from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow from homeassistant.core import callback from homeassistant.helpers.aiohttp_client import async_create_clientsession from .core import core_utils -from .core.const import DOMAIN, PID_WIFI, PID_WIFI_BLE, PID_BLE +from .core.const import DOMAIN, PID_BLE, PID_WIFI, PID_WIFI_BLE from .core.xiaomi_cloud import MiCloud from .hass import hass_utils diff --git a/custom_components/xiaomi_gateway3/core/converters/lumi.py b/custom_components/xiaomi_gateway3/core/converters/lumi.py index 9f0e024d..6fee1b3c 100644 --- a/custom_components/xiaomi_gateway3/core/converters/lumi.py +++ b/custom_components/xiaomi_gateway3/core/converters/lumi.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING from .base import BaseConv -from .const import BUTTON, UNKNOWN, BUTTON_BOTH +from .const import BUTTON, BUTTON_BOTH, UNKNOWN if TYPE_CHECKING: from ..device import XDevice diff --git a/custom_components/xiaomi_gateway3/core/converters/silabs.py b/custom_components/xiaomi_gateway3/core/converters/silabs.py index f8c67939..c77cdfc8 100644 --- a/custom_components/xiaomi_gateway3/core/converters/silabs.py +++ b/custom_components/xiaomi_gateway3/core/converters/silabs.py @@ -2,20 +2,20 @@ from zigpy.zcl import Cluster from zigpy.zcl.foundation import ( - GENERAL_COMMANDS, CommandSchema, + GENERAL_COMMANDS, + GeneralCommand, TypeValue, ZCLCommandDef, ZCLHeader, ) -from zigpy.zcl.foundation import GeneralCommand from zigpy.zdo import ZDO from zigpy.zdo.types import ( - ZDOCmd, Neighbors, NodeDescriptor, SizePrefixedSimpleDescriptor, Status as ZDOStatus, + ZDOCmd, ) try: diff --git a/custom_components/xiaomi_gateway3/core/converters/zigbee.py b/custom_components/xiaomi_gateway3/core/converters/zigbee.py index 03417418..328995d7 100644 --- a/custom_components/xiaomi_gateway3/core/converters/zigbee.py +++ b/custom_components/xiaomi_gateway3/core/converters/zigbee.py @@ -4,11 +4,11 @@ from zigpy.zcl.clusters.closures import WindowCovering from zigpy.zcl.clusters.general import ( AnalogInput, + Basic, LevelControl, MultistateInput, OnOff, PowerConfiguration, - Basic, ) from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement from zigpy.zcl.clusters.lighting import Color @@ -22,7 +22,7 @@ from zigpy.zcl.clusters.smartenergy import Metering from .base import BaseConv, decode_time -from .const import BUTTON_SINGLE, BUTTON_DOUBLE, BUTTON_HOLD +from .const import BUTTON_DOUBLE, BUTTON_HOLD, BUTTON_SINGLE from .silabs import * if TYPE_CHECKING: @@ -386,17 +386,20 @@ def decode(self, device: "XDevice", payload: dict, data: dict): except: pass + @dataclass class ZLifeControlHumidity(ZMathConv): cluster_id = TemperatureMeasurement.cluster_id attr_id = TemperatureMeasurement.AttributeDefs.min_measured_value.id multiply: float = 0.01 + @dataclass class ZLifeControlECO2(ZMathConv): cluster_id = TemperatureMeasurement.cluster_id attr_id = TemperatureMeasurement.AttributeDefs.max_measured_value.id + @dataclass class ZLifeControlVOC(ZMathConv): cluster_id = TemperatureMeasurement.cluster_id diff --git a/custom_components/xiaomi_gateway3/core/core_utils.py b/custom_components/xiaomi_gateway3/core/core_utils.py index eadf93f3..3b77c478 100644 --- a/custom_components/xiaomi_gateway3/core/core_utils.py +++ b/custom_components/xiaomi_gateway3/core/core_utils.py @@ -5,7 +5,7 @@ import random import socket -from .const import SUPPORTED_MODELS, PID_BLE +from .const import PID_BLE, SUPPORTED_MODELS from .mini_miio import AsyncMiIO from .shell.session import Session from .xiaomi_cloud import MiCloud diff --git a/custom_components/xiaomi_gateway3/core/device.py b/custom_components/xiaomi_gateway3/core/device.py index 50f1db18..e5650092 100644 --- a/custom_components/xiaomi_gateway3/core/device.py +++ b/custom_components/xiaomi_gateway3/core/device.py @@ -3,9 +3,9 @@ import re import time from functools import cached_property -from typing import Callable, TYPE_CHECKING, TypedDict, Optional +from typing import Callable, Optional, TYPE_CHECKING, TypedDict -from .const import GATEWAY, ZIGBEE, BLE, MESH, GROUP, MATTER +from .const import BLE, GATEWAY, GROUP, MATTER, MESH, ZIGBEE from .converters import silabs from .converters.base import BaseConv, decode_time, encode_time from .converters.lumi import LUMI_GLOBALS diff --git a/custom_components/xiaomi_gateway3/core/gate/base.py b/custom_components/xiaomi_gateway3/core/gate/base.py index 0ef67cad..fce36298 100644 --- a/custom_components/xiaomi_gateway3/core/gate/base.py +++ b/custom_components/xiaomi_gateway3/core/gate/base.py @@ -2,12 +2,12 @@ import logging import time from functools import cached_property -from logging import Logger, DEBUG +from logging import DEBUG, Logger from typing import Callable from ..const import GATEWAY from ..device import XDevice, XDeviceExtra -from ..mini_mqtt import MiniMQTT, MQTTMessage +from ..mini_mqtt import MQTTMessage, MiniMQTT EVENT_ADD_DEVICE = "add_device" EVENT_REMOVE_DEVICE = "remove_device" diff --git a/custom_components/xiaomi_gateway3/core/gate/mesh.py b/custom_components/xiaomi_gateway3/core/gate/mesh.py index 2e3734fe..8a7f2e7d 100644 --- a/custom_components/xiaomi_gateway3/core/gate/mesh.py +++ b/custom_components/xiaomi_gateway3/core/gate/mesh.py @@ -1,7 +1,7 @@ import time from .base import XGateway -from ..const import MESH, GROUP +from ..const import GROUP, MESH from ..mini_mqtt import MQTTMessage from ..shell.shell_mgw import ShellMGW diff --git a/custom_components/xiaomi_gateway3/core/gate/silabs.py b/custom_components/xiaomi_gateway3/core/gate/silabs.py index cf659eeb..a4d22b37 100644 --- a/custom_components/xiaomi_gateway3/core/gate/silabs.py +++ b/custom_components/xiaomi_gateway3/core/gate/silabs.py @@ -4,7 +4,7 @@ from logging import DEBUG from .base import XGateway -from ..const import ZIGBEE, GATEWAY +from ..const import GATEWAY, ZIGBEE from ..converters import silabs from ..converters.zigbee import ZConverter from ..device import XDevice, hex_to_ieee diff --git a/custom_components/xiaomi_gateway3/core/gateway.py b/custom_components/xiaomi_gateway3/core/gateway.py index 1d642075..eec6447f 100644 --- a/custom_components/xiaomi_gateway3/core/gateway.py +++ b/custom_components/xiaomi_gateway3/core/gateway.py @@ -1,7 +1,7 @@ import asyncio from . import core_utils -from .const import GATEWAY, ZIGBEE, MESH, GROUP, MATTER +from .const import GATEWAY, GROUP, MATTER, MESH, ZIGBEE from .device import XDevice from .gate.base import EVENT_MQTT_PUBLISH, EVENT_TIMER from .gate.ble import BLEGateway diff --git a/custom_components/xiaomi_gateway3/core/shell/shell_e1.py b/custom_components/xiaomi_gateway3/core/shell/shell_e1.py index e3e0e026..a973913f 100644 --- a/custom_components/xiaomi_gateway3/core/shell/shell_e1.py +++ b/custom_components/xiaomi_gateway3/core/shell/shell_e1.py @@ -2,7 +2,7 @@ import re from .base import ShellBase -from .const import OPENMIIO_MD5_ARM, OPENMIIO_URL_ARM, OPENMIIO_CMD +from .const import OPENMIIO_CMD, OPENMIIO_MD5_ARM, OPENMIIO_URL_ARM class ShellE1(ShellBase): diff --git a/custom_components/xiaomi_gateway3/core/shell/shell_mgw.py b/custom_components/xiaomi_gateway3/core/shell/shell_mgw.py index cbe46d85..7df33f39 100644 --- a/custom_components/xiaomi_gateway3/core/shell/shell_mgw.py +++ b/custom_components/xiaomi_gateway3/core/shell/shell_mgw.py @@ -2,7 +2,7 @@ import re from .base import ShellBase -from .const import OPENMIIO_MD5_MIPS, OPENMIIO_URL_MIPS, OPENMIIO_CMD +from .const import OPENMIIO_CMD, OPENMIIO_MD5_MIPS, OPENMIIO_URL_MIPS from ..unqlite import SQLite CHECK_FIRMWARE = "/data/busybox lsattr /data/firmware/firmware_ota.bin" diff --git a/custom_components/xiaomi_gateway3/cover.py b/custom_components/xiaomi_gateway3/cover.py index 9c03adf8..af5d5203 100644 --- a/custom_components/xiaomi_gateway3/cover.py +++ b/custom_components/xiaomi_gateway3/cover.py @@ -1,5 +1,5 @@ from homeassistant.components.cover import CoverEntity -from homeassistant.const import STATE_OPENING, STATE_CLOSING +from homeassistant.const import STATE_CLOSING, STATE_OPENING from homeassistant.helpers.restore_state import RestoreEntity from .core.gate.base import XGateway diff --git a/custom_components/xiaomi_gateway3/device_trigger.py b/custom_components/xiaomi_gateway3/device_trigger.py index d5d3dff0..6fc241eb 100644 --- a/custom_components/xiaomi_gateway3/device_trigger.py +++ b/custom_components/xiaomi_gateway3/device_trigger.py @@ -19,11 +19,11 @@ from .core.const import DOMAIN from .core.converters.base import BaseConv, ConstConv, MapConv from .core.converters.const import ( - BUTTON_SINGLE, BUTTON_DOUBLE, - BUTTON_TRIPLE, BUTTON_HOLD, BUTTON_RELEASE, + BUTTON_SINGLE, + BUTTON_TRIPLE, ) from .core.converters.mibeacon import BLEMapConv from .core.devices import DEVICES diff --git a/custom_components/xiaomi_gateway3/hass/add_entitites.py b/custom_components/xiaomi_gateway3/hass/add_entitites.py index 22fd4160..3b167d48 100644 --- a/custom_components/xiaomi_gateway3/hass/add_entitites.py +++ b/custom_components/xiaomi_gateway3/hass/add_entitites.py @@ -5,8 +5,8 @@ from homeassistant.helpers import device_registry, entity_registry from .entity import XEntity -from .. import XDevice, MultiGateway -from ..core.const import DOMAIN, GATEWAY, BLE, MATTER, MESH, ZIGBEE +from .. import MultiGateway, XDevice +from ..core.const import BLE, DOMAIN, GATEWAY, MATTER, MESH, ZIGBEE from ..core.converters.base import BaseConv from ..core.gate.base import EVENT_ADD_DEVICE, EVENT_REMOVE_DEVICE diff --git a/custom_components/xiaomi_gateway3/hass/entity.py b/custom_components/xiaomi_gateway3/hass/entity.py index e49a9f9a..9aeafa80 100644 --- a/custom_components/xiaomi_gateway3/hass/entity.py +++ b/custom_components/xiaomi_gateway3/hass/entity.py @@ -1,7 +1,7 @@ import logging from datetime import datetime, timezone from functools import cached_property -from typing import TYPE_CHECKING, Callable +from typing import Callable, TYPE_CHECKING from homeassistant.helpers.device_registry import ( CONNECTION_BLUETOOTH, @@ -14,7 +14,7 @@ from homeassistant.helpers.template import Template from .entity_description import setup_entity_description -from ..core.const import DOMAIN, GATEWAY, ZIGBEE, BLE, MESH +from ..core.const import BLE, DOMAIN, GATEWAY, MESH, ZIGBEE from ..core.converters.base import BaseConv if TYPE_CHECKING: diff --git a/custom_components/xiaomi_gateway3/hass/entity_description.py b/custom_components/xiaomi_gateway3/hass/entity_description.py index 1f318387..80e2e2ae 100644 --- a/custom_components/xiaomi_gateway3/hass/entity_description.py +++ b/custom_components/xiaomi_gateway3/hass/entity_description.py @@ -1,4 +1,5 @@ """Set entity attributes based on converter settings.""" + from homeassistant.components.binary_sensor import BinarySensorDeviceClass from homeassistant.components.cover import CoverDeviceClass from homeassistant.components.number import NumberDeviceClass @@ -13,8 +14,8 @@ MINOR_VERSION, PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, - UnitOfElectricPotential, UnitOfElectricCurrent, + UnitOfElectricPotential, UnitOfEnergy, UnitOfLength, UnitOfPower, @@ -92,7 +93,11 @@ "smoke_density": {"icon": "mdi:google-circles-communities", "units": "% obs/ft"}, "supply": {"icon": "mdi:gauge", "units": PERCENTAGE}, "tvoc": {"icon": "mdi:cloud", "units": CONCENTRATION_PARTS_PER_BILLION}, - "eco_two": {"name": "eCO2", "icon": "mdi:molecule-co2", "units": CONCENTRATION_PARTS_PER_MILLION}, + "eco_two": { + "name": "eCO2", + "icon": "mdi:molecule-co2", + "units": CONCENTRATION_PARTS_PER_MILLION, + }, ## # stats sensors "binary_sensor.gateway": { diff --git a/custom_components/xiaomi_gateway3/hass/hass_utils.py b/custom_components/xiaomi_gateway3/hass/hass_utils.py index b4996585..4da955f8 100644 --- a/custom_components/xiaomi_gateway3/hass/hass_utils.py +++ b/custom_components/xiaomi_gateway3/hass/hass_utils.py @@ -6,7 +6,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant -from homeassistant.helpers import entity_registry, device_registry +from homeassistant.helpers import device_registry, entity_registry from homeassistant.helpers.aiohttp_client import ( async_create_clientsession, async_get_clientsession, @@ -17,7 +17,7 @@ from .. import XDevice from ..core import core_utils -from ..core.const import DOMAIN, ZIGBEE, SUPPORTED_MODELS +from ..core.const import DOMAIN, SUPPORTED_MODELS, ZIGBEE from ..core.gate.base import XGateway from ..core.xiaomi_cloud import MiCloud diff --git a/custom_components/xiaomi_gateway3/light.py b/custom_components/xiaomi_gateway3/light.py index 16d246d7..dc62ed5a 100644 --- a/custom_components/xiaomi_gateway3/light.py +++ b/custom_components/xiaomi_gateway3/light.py @@ -3,9 +3,6 @@ from functools import cached_property from homeassistant.components.light import ( - ColorMode, - LightEntity, - LightEntityFeature, ATTR_BRIGHTNESS, ATTR_COLOR_MODE, ATTR_COLOR_TEMP, @@ -13,6 +10,9 @@ ATTR_HS_COLOR, ATTR_RGB_COLOR, ATTR_TRANSITION, + ColorMode, + LightEntity, + LightEntityFeature, ) from homeassistant.helpers.restore_state import RestoreEntity diff --git a/custom_components/xiaomi_gateway3/number.py b/custom_components/xiaomi_gateway3/number.py index c5b1bce0..9c518fb7 100644 --- a/custom_components/xiaomi_gateway3/number.py +++ b/custom_components/xiaomi_gateway3/number.py @@ -1,4 +1,4 @@ -from homeassistant.components.number import NumberEntity, DEFAULT_STEP, NumberMode +from homeassistant.components.number import DEFAULT_STEP, NumberEntity, NumberMode from homeassistant.helpers.restore_state import RestoreEntity from .hass.entity import XEntity diff --git a/custom_components/xiaomi_gateway3/select.py b/custom_components/xiaomi_gateway3/select.py index 6f7b6565..6ce08de4 100644 --- a/custom_components/xiaomi_gateway3/select.py +++ b/custom_components/xiaomi_gateway3/select.py @@ -2,7 +2,7 @@ from homeassistant.helpers.restore_state import RestoreEntity from .core import ezsp -from .core.const import GATEWAY, ZIGBEE, MESH, MATTER +from .core.const import GATEWAY, MATTER, MESH, ZIGBEE from .core.gateway import MultiGateway from .hass import hass_utils from .hass.entity import XEntity diff --git a/tests/test_automations.py b/tests/test_automations.py index 85ef424d..e293ae81 100644 --- a/tests/test_automations.py +++ b/tests/test_automations.py @@ -1,6 +1,5 @@ -from custom_components.xiaomi_gateway3.device_trigger import get_actions - from custom_components.xiaomi_gateway3.core.device import XDevice +from custom_components.xiaomi_gateway3.device_trigger import get_actions def test_buttons(): diff --git a/tests/test_conv_silabs.py b/tests/test_conv_silabs.py index 4a4ce66f..408e4ed3 100644 --- a/tests/test_conv_silabs.py +++ b/tests/test_conv_silabs.py @@ -1,5 +1,4 @@ from zigpy.zcl.clusters.general import OnOff -from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement from custom_components.xiaomi_gateway3.core.converters import silabs from custom_components.xiaomi_gateway3.core.converters.silabs import zcl_write diff --git a/tests/test_migrate.py b/tests/test_migrate.py index 70dc80fb..3ba8826c 100644 --- a/tests/test_migrate.py +++ b/tests/test_migrate.py @@ -1,5 +1,5 @@ from custom_components.xiaomi_gateway3.core.const import DOMAIN -from custom_components.xiaomi_gateway3.hass.hass_utils import migrate_uid, migrate_attr +from custom_components.xiaomi_gateway3.hass.hass_utils import migrate_attr, migrate_uid def test_migrate_uid():