Skip to content

Commit

Permalink
Merge pull request #119 from dmamontov/version/3.0.0
Browse files Browse the repository at this point in the history
Many bugs
  • Loading branch information
dmamontov authored Mar 13, 2023
2 parents 221730a + f17e7dd commit 8442d60
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 103 deletions.
85 changes: 44 additions & 41 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion custom_components/miwifi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def async_start(with_sleep: bool = False) -> None:
if with_sleep:
await asyncio.sleep(DEFAULT_SLEEP)

hass.config_entries.async_setup_platforms(entry, PLATFORMS)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

if is_new:
await async_start()
Expand Down
1 change: 1 addition & 0 deletions custom_components/miwifi/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async def async_setup_entry(
async_add_entities(entities)


# pylint: disable=too-many-ancestors
class MiWifiButton(MiWifiEntity, ButtonEntity):
"""MiWifi button entry."""

Expand Down
5 changes: 0 additions & 5 deletions custom_components/miwifi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@
CLIENT_NONCE_TYPE: Final = 0
CLIENT_PUBLIC_KEY: Final = "a2ffa5c9be07488bbb04a3a47d3c5f6a"

"""Device classes"""
DEVICE_CLASS_MIWIFI_SIGNAL_STRENGTH: Final = "miwifi__signal_strength"
DEVICE_CLASS_MIWIFI_DEVICE_TRACKER: Final = "miwifi__device_tracker"
DEVICE_CLASS_MIWIFI_MODE: Final = "miwifi__mode"

"""Services"""
SERVICE_CALC_PASSWD: Final = "calc_passwd"
SERVICE_REQUEST: Final = "request"
Expand Down
5 changes: 2 additions & 3 deletions custom_components/miwifi/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@
CONF_STAY_ONLINE,
DEFAULT_CALL_DELAY,
DEFAULT_STAY_ONLINE,
DEVICE_CLASS_MIWIFI_DEVICE_TRACKER,
DOMAIN,
SIGNAL_NEW_DEVICE,
UPDATER,
)
from .enum import Connection
from .enum import Connection, DeviceClass
from .helper import (
detect_manufacturer,
generate_entity_id,
Expand Down Expand Up @@ -147,7 +146,7 @@ class MiWifiDeviceTracker(ScannerEntity, CoordinatorEntity):
"""MiWifi device tracker entry."""

_attr_attribution: str = ATTRIBUTION
_attr_device_class: str = DEVICE_CLASS_MIWIFI_DEVICE_TRACKER
_attr_device_class: str = DeviceClass.DEVICE_TRACKER

_configuration_port: int | None = None
_is_connected: bool = False
Expand Down
13 changes: 12 additions & 1 deletion custom_components/miwifi/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from enum import Enum, IntEnum
from enum import Enum, IntEnum # type: ignore

from homeassistant.backports.enum import StrEnum

Expand Down Expand Up @@ -180,6 +180,14 @@ class EncryptionAlgorithm(StrEnum):
SHA256 = "sha256"


class DeviceClass(StrEnum):
"""DeviceClass enum"""

MODE = "miwifi__mode"
SIGNAL_STRENGTH = "miwifi__signal_strength"
DEVICE_TRACKER = "miwifi__device_tracker"


class Model(str, Enum):
"""Model enum"""

Expand Down Expand Up @@ -239,7 +247,10 @@ def __str__(self) -> str:
RB01 = "rb01" # 2021.10.28
RA82 = "ra82" # 2021.11.01
CR8808 = "cr8808" # 2021.11.26
RB02 = "rb02" # 2022.01.18
RB04 = "rb04" # 2022.02.17
RA74 = "ra74" # 2022.03.18
RB06 = "rb06" # 2022.04.02
RB08 = "rb08" # 2022.07.04
R4AV2 = "r4av2" # 2022
CB0401 = "cb0401" # 2022
1 change: 1 addition & 0 deletions custom_components/miwifi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ async def async_setup_entry(
async_add_entities(entities)


# pylint: disable=too-many-ancestors
class MiWifiLight(MiWifiEntity, LightEntity):
"""MiWifi light entry."""

Expand Down
142 changes: 109 additions & 33 deletions custom_components/miwifi/manifest.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,122 @@
{
"domain": "miwifi",
"name": "MiWiFi",
"version": "2.9.0",
"documentation": "https://github.com/dmamontov/hass-miwifi/wiki",
"issue_tracker": "https://github.com/dmamontov/hass-miwifi/issues",
"codeowners": [
"@dmamontov"
],
"config_flow": true,
"requirements": [],
"dependencies": ["http"],
"codeowners": ["@dmamontov"],
"dependencies": [
"http"
],
"dhcp": [
{
"hostname": "miwifi-*",
"macaddress": "C85CCC*"
},
{
"hostname": "miwifi-*",
"macaddress": "D43538*"
},
{
"hostname": "miwifi-*",
"macaddress": "649E31*"
},
{
"hostname": "miwifi-*",
"macaddress": "5C0214*"
},
{
"hostname": "miwifi-*",
"macaddress": "CCB5D1*"
},
{
"hostname": "miwifi-*",
"macaddress": "68ABBC*"
},
{
"hostname": "miwifi-*",
"macaddress": "8CDEF9*"
},
{
"hostname": "miwifi-*",
"macaddress": "DCED83*"
},
{
"hostname": "miwifi-*",
"macaddress": "3CCD57*"
},
{
"hostname": "miwifi-*",
"macaddress": "64644A*"
},
{
"hostname": "miwifi-*",
"macaddress": "5448E6*"
},
{
"hostname": "miwifi-*",
"macaddress": "6490C1*"
},
{
"hostname": "miwifi-*",
"macaddress": "44237C*"
},
{
"hostname": "miwifi-*",
"macaddress": "5CE50C*"
},
{
"hostname": "miwifi-*",
"macaddress": "50D2F5*"
},
{
"hostname": "miwifi-*",
"macaddress": "88C397*"
},
{
"hostname": "miwifi-*",
"macaddress": "8C53C3*"
},
{
"hostname": "miwifi-*",
"macaddress": "50EC50*"
},
{
"hostname": "miwifi-*",
"macaddress": "EC4D3E*"
},
{
"hostname": "miwifi-*",
"macaddress": "28D127*"
},
{
"hostname": "miwifi-*",
"macaddress": "7CC294*"
},
{
"hostname": "miwifi-*",
"macaddress": "9C9D7E*"
},
{
"hostname": "miwifi-*",
"macaddress": "B460ED*"
},
{
"hostname": "miwifi-*",
"macaddress": "58B623*"
}
],
"documentation": "https://github.com/dmamontov/hass-miwifi/wiki",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/dmamontov/hass-miwifi/issues",
"quality_scale": "platinum",
"requirements": [],
"ssdp": [
{
"st": "upnp:rootdevice",
"manufacturer": "Xiaomi",
"deviceType": "urn:schemas-upnp-org:device:InternetGatewayDevice:1"
}
],
"dhcp": [
{"hostname": "miwifi-*", "macaddress": "C85CCC*"},
{"hostname": "miwifi-*", "macaddress": "D43538*"},
{"hostname": "miwifi-*", "macaddress": "649E31*"},
{"hostname": "miwifi-*", "macaddress": "5C0214*"},
{"hostname": "miwifi-*", "macaddress": "CCB5D1*"},
{"hostname": "miwifi-*", "macaddress": "68ABBC*"},
{"hostname": "miwifi-*", "macaddress": "8CDEF9*"},
{"hostname": "miwifi-*", "macaddress": "DCED83*"},
{"hostname": "miwifi-*", "macaddress": "3CCD57*"},
{"hostname": "miwifi-*", "macaddress": "64644A*"},
{"hostname": "miwifi-*", "macaddress": "5448E6*"},
{"hostname": "miwifi-*", "macaddress": "6490C1*"},
{"hostname": "miwifi-*", "macaddress": "44237C*"},
{"hostname": "miwifi-*", "macaddress": "5CE50C*"},
{"hostname": "miwifi-*", "macaddress": "50D2F5*"},
{"hostname": "miwifi-*", "macaddress": "88C397*"},
{"hostname": "miwifi-*", "macaddress": "8C53C3*"},
{"hostname": "miwifi-*", "macaddress": "50EC50*"},
{"hostname": "miwifi-*", "macaddress": "EC4D3E*"},
{"hostname": "miwifi-*", "macaddress": "28D127*"},
{"hostname": "miwifi-*", "macaddress": "7CC294*"},
{"hostname": "miwifi-*", "macaddress": "9C9D7E*"},
{"hostname": "miwifi-*", "macaddress": "B460ED*"},
{"hostname": "miwifi-*", "macaddress": "58B623*"}
]
}
"version": "3.0.0"
}
9 changes: 4 additions & 5 deletions custom_components/miwifi/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@
ATTR_WIFI_5_0_DATA,
ATTR_WIFI_5_0_GAME_DATA,
ATTR_WIFI_ADAPTER_LENGTH,
DEVICE_CLASS_MIWIFI_SIGNAL_STRENGTH,
)
from .entity import MiWifiEntity
from .enum import Wifi
from .enum import Wifi, DeviceClass
from .exceptions import LuciError
from .updater import LuciUpdater, async_get_updater

Expand Down Expand Up @@ -111,23 +110,23 @@
key=ATTR_SELECT_WIFI_2_4_SIGNAL_STRENGTH,
name=ATTR_SELECT_WIFI_2_4_SIGNAL_STRENGTH_NAME,
icon=ICONS[f"{ATTR_SELECT_WIFI_2_4_SIGNAL_STRENGTH}_max"],
device_class=DEVICE_CLASS_MIWIFI_SIGNAL_STRENGTH,
device_class=DeviceClass.SIGNAL_STRENGTH,
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
),
SelectEntityDescription(
key=ATTR_SELECT_WIFI_5_0_SIGNAL_STRENGTH,
name=ATTR_SELECT_WIFI_5_0_SIGNAL_STRENGTH_NAME,
icon=ICONS[f"{ATTR_SELECT_WIFI_5_0_SIGNAL_STRENGTH}_max"],
device_class=DEVICE_CLASS_MIWIFI_SIGNAL_STRENGTH,
device_class=DeviceClass.SIGNAL_STRENGTH,
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
),
SelectEntityDescription(
key=ATTR_SELECT_WIFI_5_0_GAME_SIGNAL_STRENGTH,
name=ATTR_SELECT_WIFI_5_0_GAME_SIGNAL_STRENGTH_NAME,
icon=ICONS[f"{ATTR_SELECT_WIFI_5_0_GAME_SIGNAL_STRENGTH}_max"],
device_class=DEVICE_CLASS_MIWIFI_SIGNAL_STRENGTH,
device_class=DeviceClass.SIGNAL_STRENGTH,
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
),
Expand Down
4 changes: 2 additions & 2 deletions custom_components/miwifi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
ATTR_SENSOR_WAN_UPLOAD_SPEED,
ATTR_SENSOR_WAN_UPLOAD_SPEED_NAME,
ATTR_STATE,
DEVICE_CLASS_MIWIFI_MODE,
)
from .entity import MiWifiEntity
from .enum import DeviceClass
from .updater import LuciUpdater, async_get_updater

PARALLEL_UPDATES = 0
Expand Down Expand Up @@ -118,7 +118,7 @@
key=ATTR_SENSOR_MODE,
name=ATTR_SENSOR_MODE_NAME,
icon="mdi:transit-connection-variant",
device_class=DEVICE_CLASS_MIWIFI_MODE,
device_class=DeviceClass.MODE,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=True,
),
Expand Down
10 changes: 7 additions & 3 deletions custom_components/miwifi/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
SERVICE_CALC_PASSWD,
SERVICE_REQUEST,
)
from .exceptions import LuciError
from .updater import LuciUpdater, async_get_updater

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -132,9 +133,12 @@ async def async_call_service(self, service: ServiceCallType) -> None:

_data: dict = dict(service.data)

response: dict = await updater.luci.get(
uri := _data.get(CONF_URI), body := _data.get(CONF_BODY, {}) # type: ignore
)
try:
response: dict = await updater.luci.get(
uri := _data.get(CONF_URI), body := _data.get(CONF_BODY, {}) # type: ignore
)
except LuciError:
return

device: dr.DeviceEntry | None = dr.async_get(self.hass).async_get_device(
set(),
Expand Down
1 change: 1 addition & 0 deletions custom_components/miwifi/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ async def async_setup_entry(
async_add_entities(entities)


# pylint: disable=too-many-ancestors
class MiWifiSwitch(MiWifiEntity, SwitchEntity):
"""MiWifi switch entry."""

Expand Down
1 change: 1 addition & 0 deletions custom_components/miwifi/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ async def async_setup_entry(
async_add_entities(entities)


# pylint: disable=too-many-ancestors
class MiWifiUpdate(MiWifiEntity, UpdateEntity):
"""MiWifi update entry."""

Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "MiWiFi",
"render_readme": true,
"homeassistant": "2022.4.0"
"homeassistant": "2023.3.0"
}
Binary file added images/CB0401.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/R4AV2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/RB02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 2 additions & 6 deletions tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ async def test_install(hass: HomeAssistant) -> None:
"custom_components.miwifi.async_start_discovery", return_value=None
), patch(
"custom_components.miwifi.update.asyncio.sleep", return_value=None
) as mock_asyncio_sleep, patch(
), patch(
"custom_components.miwifi.device_tracker.socket.socket"
) as mock_socket:
mock_socket.return_value.recv.return_value = AsyncMock(return_value=None)
Expand Down Expand Up @@ -390,8 +390,6 @@ def _on() -> dict:
limit=None,
)

assert len(mock_asyncio_sleep.mock_calls) == 739


@pytest.mark.asyncio
async def test_install_flash_error(hass: HomeAssistant) -> None:
Expand All @@ -408,7 +406,7 @@ async def test_install_flash_error(hass: HomeAssistant) -> None:
"custom_components.miwifi.async_start_discovery", return_value=None
), patch(
"custom_components.miwifi.update.asyncio.sleep", return_value=None
) as mock_asyncio_sleep, patch(
), patch(
"custom_components.miwifi.device_tracker.socket.socket"
) as mock_socket:
mock_socket.return_value.recv.return_value = AsyncMock(return_value=None)
Expand Down Expand Up @@ -463,8 +461,6 @@ def _on() -> dict:
limit=None,
)

assert len(mock_asyncio_sleep.mock_calls) == 18


@pytest.mark.asyncio
async def test_install_error(hass: HomeAssistant) -> None:
Expand Down
Loading

0 comments on commit 8442d60

Please sign in to comment.