Skip to content

Commit 5fd727e

Browse files
authored
Refactoring to support Python 3.11 and Home Assistant 2023.6
1 parent 509d9ec commit 5fd727e

16 files changed

+276
-280
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Home Assistant custom component for control Huawei mesh routers over LAN.
44

55
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/hacs/integration)
66
[![License](https://img.shields.io/github/license/vmakeev/huawei_mesh_router)](https://github.com/vmakeev/huawei_mesh_router/blob/master/LICENSE.md)
7-
![Active installations](https://raw.githubusercontent.com/vmakeev/custom_badges_updater/main/huawei_mesh_router.svg)
7+
![Active installatons](https://img.shields.io/badge/dynamic/json?color=blue&label=active%20installations&query=$[%27huawei_mesh_router%27][%27total%27]&url=https%3A%2F%2Fanalytics.home-assistant.io%2Fcustom_integrations.json&cacheSeconds=600)
88

99
[![Release](https://img.shields.io/github/v/release/vmakeev/huawei_mesh_router)](https://github.com/vmakeev/huawei_mesh_router/releases/latest)
1010
[![ReleaseDate](https://img.shields.io/github/release-date/vmakeev/huawei_mesh_router)](https://github.com/vmakeev/huawei_mesh_router/releases/latest)
@@ -66,10 +66,13 @@ By default, Huawei mesh routers use the username `admin`, although it is not dis
6666

6767
### Advanced options
6868

69-
You can perform advanced component configuration by clicking the `CONFIGURE` button after adding it.
69+
You can perform advanced configuration of the component after adding it.
70+
To do this, click on the gear, and in the tab that opens, click `CONFIGURE`
7071

7172
![Integration](docs/images/integration.png)
7273

74+
![Integration details](docs/images/integration_details.png)
75+
7376
Advanced settings include:
7477
| Name | Default |
7578
|------------------------------------------------------------------------------------------------------------------|------------|

custom_components/huawei_mesh_router/button.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
from homeassistant.helpers.update_coordinator import CoordinatorEntity
1212

1313
from .classes import ConnectedDevice
14-
from .client.classes import MAC_ADDR
15-
from .client.huaweiapi import ACTION_REBOOT
14+
from .client.classes import MAC_ADDR, Action
1615
from .helpers import (
1716
generate_entity_id,
1817
generate_entity_name,
@@ -80,12 +79,12 @@ class HuaweiButton(CoordinatorEntity[HuaweiDataUpdateCoordinator], ButtonEntity,
8079
def __init__(
8180
self,
8281
coordinator: HuaweiDataUpdateCoordinator,
83-
action_name: str,
82+
action: Action,
8483
device_mac: MAC_ADDR | None,
8584
) -> None:
8685
"""Initialize."""
8786
super().__init__(coordinator)
88-
self._action_name: str = action_name
87+
self._action: Action = action
8988
self._device_mac: MAC_ADDR = device_mac
9089
self._attr_device_info = coordinator.get_device_info(device_mac)
9190

@@ -100,10 +99,10 @@ async def async_added_to_hass(self) -> None:
10099
self._handle_coordinator_update()
101100
if self._device_mac:
102101
_LOGGER.debug(
103-
"Button %s (%s) added to hass", self._action_name, self._device_mac
102+
"Button %s (%s) added to hass", self._action, self._device_mac
104103
)
105104
else:
106-
_LOGGER.debug("Button %s added to hass", self._action_name)
105+
_LOGGER.debug("Button %s added to hass", self._action)
107106

108107
@callback
109108
def _handle_coordinator_update(self) -> None:
@@ -112,7 +111,7 @@ def _handle_coordinator_update(self) -> None:
112111

113112
async def async_press(self) -> None:
114113
"""Triggers the button press service."""
115-
await self.coordinator.execute_action(self._action_name, self._device_mac)
114+
await self.coordinator.execute_action(self._action, self._device_mac)
116115

117116
def press(self) -> None:
118117
"""Press the button."""
@@ -131,7 +130,7 @@ def __init__(
131130
device: ConnectedDevice | None,
132131
) -> None:
133132
"""Initialize."""
134-
super().__init__(coordinator, ACTION_REBOOT, device.mac if device else None)
133+
super().__init__(coordinator, Action.REBOOT, device.mac if device else None)
135134

136135
self._attr_device_class = ButtonDeviceClass.RESTART
137136

custom_components/huawei_mesh_router/classes.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Huawei Mesh Router component classes."""
22

33
from dataclasses import dataclass
4+
from enum import StrEnum
45
from typing import Any, Dict, Iterable, Tuple
56

6-
from homeassistant.backports.enum import StrEnum
7-
87
from .client.classes import MAC_ADDR, HuaweiFilterItem
98

109
DEVICE_TAG = str
@@ -19,6 +18,22 @@ class ZoneInfo:
1918
entity_id: str
2019

2120

21+
# ---------------------------
22+
# Select
23+
# ---------------------------
24+
class Select(StrEnum):
25+
WLAN_FILTER_MODE = "wlan_filter_mode_select"
26+
ROUTER_ZONE = "router_zone_select"
27+
28+
29+
# ---------------------------
30+
# EmulatedSwitch
31+
# ---------------------------
32+
class EmulatedSwitch(StrEnum):
33+
DEVICE_ACCESS = "wlan_device_access_switch"
34+
URL_FILTER = "url_filter_switch"
35+
36+
2237
# ---------------------------
2338
# HuaweiInterfaceType
2439
# ---------------------------

custom_components/huawei_mesh_router/client/classes.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass
6-
from enum import Enum, IntEnum
6+
from enum import Enum, IntEnum, StrEnum
77
from typing import Any, Dict, Final, Iterable, TypeAlias
88

99
VENDOR_CLASS_ID_ROUTER: Final = "router"
@@ -14,6 +14,45 @@
1414
MAC_ADDR: TypeAlias = str
1515

1616

17+
# ---------------------------
18+
# Feature
19+
# ---------------------------
20+
class Feature(StrEnum):
21+
NFC: Final = "feature_nfc"
22+
URL_FILTER = "feature_url_filter"
23+
WIFI_80211R = "feature_wifi_80211r"
24+
WIFI_TWT = "feature_wifi_twt"
25+
WLAN_FILTER = "feature_wlan_filter"
26+
DEVICE_TOPOLOGY = "feature_device_topology"
27+
GUEST_NETWORK = "feature_guest_network"
28+
29+
30+
# ---------------------------
31+
# Switch
32+
# ---------------------------
33+
class Switch(StrEnum):
34+
NFC: Final = "nfc_switch"
35+
WIFI_80211R = "wifi_80211r_switch"
36+
WIFI_TWT = "wifi_twt_switch"
37+
WLAN_FILTER = "wlan_filter_switch"
38+
GUEST_NETWORK = "guest_network_switch"
39+
40+
41+
# ---------------------------
42+
# Action
43+
# ---------------------------
44+
class Action(StrEnum):
45+
REBOOT: Final = "reboot_action"
46+
47+
48+
# ---------------------------
49+
# Frequency
50+
# ---------------------------
51+
class Frequency(StrEnum):
52+
WIFI_2_4_GHZ = "2.4GHz"
53+
WIFI_5_GHZ = "5GHz"
54+
55+
1756
# ---------------------------
1857
# FilterAction
1958
# ---------------------------

custom_components/huawei_mesh_router/client/const.py

-20
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,8 @@
33
WIFI_SECURITY_OPEN: Final = "none"
44
WIFI_SECURITY_ENCRYPTED: Final = "tkip"
55

6-
SWITCH_NFC: Final = "nfc_switch"
7-
SWITCH_WIFI_80211R: Final = "wifi_80211r_switch"
8-
SWITCH_WIFI_TWT: Final = "wifi_twt_switch"
9-
SWITCH_WLAN_FILTER: Final = "wlan_filter_switch"
10-
SWITCH_URL_FILTER: Final = "url_filter_switch"
11-
SWITCH_GUEST_NETWORK: Final = "guest_network_switch"
12-
13-
FREQUENCY_2_4_GHZ: Final = "2.4GHz"
14-
FREQUENCY_5_GHZ: Final = "5GHz"
15-
16-
ACTION_REBOOT: Final = "reboot_action"
17-
186
CONNECTED_VIA_ID_PRIMARY: Final = "primary"
197

20-
FEATURE_NFC: Final = "feature_nfc"
21-
FEATURE_URL_FILTER: Final = "feature_url_filter"
22-
FEATURE_WIFI_80211R: Final = "feature_wifi_80211r"
23-
FEATURE_WIFI_TWT: Final = "feature_wifi_twt"
24-
FEATURE_WLAN_FILTER: Final = "feature_wlan_filter"
25-
FEATURE_DEVICE_TOPOLOGY: Final = "feature_device_topology"
26-
FEATURE_GUEST_NETWORK: Final = "feature_guest_network"
27-
288
URL_DEVICE_INFO: Final = "api/system/deviceinfo"
299
URL_DEVICE_TOPOLOGY: Final = "api/device/topology"
3010
URL_HOST_INFO: Final = "api/system/HostInfo"

0 commit comments

Comments
 (0)