Skip to content

Commit

Permalink
Optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Dec 25, 2024
1 parent 4ff8e70 commit 7935a3b
Show file tree
Hide file tree
Showing 26 changed files with 48 additions and 43 deletions.
3 changes: 1 addition & 2 deletions custom_components/xiaomi_gateway3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions custom_components/xiaomi_gateway3/climate.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions custom_components/xiaomi_gateway3/config_flow.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/core/converters/lumi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions custom_components/xiaomi_gateway3/core/converters/silabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions custom_components/xiaomi_gateway3/core/converters/zigbee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/core/core_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/xiaomi_gateway3/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/xiaomi_gateway3/core/gate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/core/gate/mesh.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/core/gate/silabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/core/gateway.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/core/shell/shell_e1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/core/shell/shell_mgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/cover.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/xiaomi_gateway3/device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/xiaomi_gateway3/hass/add_entitites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions custom_components/xiaomi_gateway3/hass/entity.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions custom_components/xiaomi_gateway3/hass/entity_description.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,8 +14,8 @@
MINOR_VERSION,
PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
UnitOfElectricPotential,
UnitOfElectricCurrent,
UnitOfElectricPotential,
UnitOfEnergy,
UnitOfLength,
UnitOfPower,
Expand Down Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions custom_components/xiaomi_gateway3/hass/hass_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions custom_components/xiaomi_gateway3/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from functools import cached_property

from homeassistant.components.light import (
ColorMode,
LightEntity,
LightEntityFeature,
ATTR_BRIGHTNESS,
ATTR_COLOR_MODE,
ATTR_COLOR_TEMP,
ATTR_EFFECT,
ATTR_HS_COLOR,
ATTR_RGB_COLOR,
ATTR_TRANSITION,
ColorMode,
LightEntity,
LightEntityFeature,
)
from homeassistant.helpers.restore_state import RestoreEntity

Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/number.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/test_automations.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
1 change: 0 additions & 1 deletion tests/test_conv_silabs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_migrate.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down

0 comments on commit 7935a3b

Please sign in to comment.