Skip to content

Commit

Permalink
New version
Browse files Browse the repository at this point in the history
  • Loading branch information
ΠœΠ°ΠΌΠΎΠ½Ρ‚ΠΎΠ² Π”ΠΌΠΈΡ‚Ρ€ΠΈΠΉ authored and ΠœΠ°ΠΌΠΎΠ½Ρ‚ΠΎΠ² Π”ΠΌΠΈΡ‚Ρ€ΠΈΠΉ committed Dec 19, 2022
1 parent 0d526c2 commit c983090
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 95 deletions.
119 changes: 60 additions & 59 deletions README.md

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions custom_components/miwifi/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,11 @@ def configuration_url(self) -> str | None:

_schema: str = "https" if self._configuration_port == 443 else "http"

_url: str = f"{_schema}://{self.ip_address}:{self._configuration_port}"

if self._configuration_port in [80, 443]:
_url = f"{_schema}://{self.ip_address}"

return _url
return (
f"{_schema}://{self.ip_address}"
if self._configuration_port in [80, 443]
else f"{_schema}://{self.ip_address}:{self._configuration_port}"
)

@property
def device_info(self) -> DeviceInfo: # pylint: disable=overridden-final-method
Expand Down Expand Up @@ -417,7 +416,7 @@ def _update_entry(self, track_device: dict) -> dict:
:return dict
"""

entry_id: str = track_device.get(ATTR_TRACKER_ENTRY_ID, None)
entry_id: str | None = track_device.get(ATTR_TRACKER_ENTRY_ID)

device_registry: dr.DeviceRegistry = dr.async_get(self.hass)
device: dr.DeviceEntry | None = device_registry.async_get_device(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/miwifi/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "miwifi",
"name": "MiWiFi",
"version": "2.8.2",
"version": "2.9.0",
"documentation": "https://github.com/dmamontov/hass-miwifi/wiki",
"issue_tracker": "https://github.com/dmamontov/hass-miwifi/issues",
"config_flow": true,
Expand Down
1 change: 1 addition & 0 deletions custom_components/miwifi/self_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
("xqsystem/init_info", "🟒"),
("misystem/status", "status"),
("xqnetwork/mode", "mode"),
("xqsystem/vpn_status", "vpn_status"),
("misystem/topo_graph", "topo_graph"),
("xqsystem/check_rom_update", "rom_update"),
("xqnetwork/wan_info", "wan_info"),
Expand Down
6 changes: 2 additions & 4 deletions custom_components/miwifi/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,15 @@ async def async_setup_entry(

updater: LuciUpdater = async_get_updater(hass, config_entry.entry_id)

entities: list[MiWifiUpdate] = [
if entities := [
MiWifiUpdate(
f"{config_entry.entry_id}-{description.key}",
description,
updater,
)
for description in MIWIFI_UPDATES
if description.key != ATTR_UPDATE_FIRMWARE or updater.supports_update
]

if entities:
]:
async_add_entities(entities)


Expand Down
33 changes: 16 additions & 17 deletions custom_components/miwifi/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,21 +529,22 @@ async def _async_prepare_vpn(self, data: dict) -> None:
:param data: dict
"""

response: dict = await self.luci.vpn_status()

data |= {
ATTR_SENSOR_VPN_UPTIME: 0,
ATTR_BINARY_SENSOR_VPN_STATE: False,
}
with contextlib.suppress(LuciError):
response: dict = await self.luci.vpn_status()

if "uptime" in response:
data |= {
ATTR_SENSOR_VPN_UPTIME: str(
timedelta(seconds=int(float(response["uptime"])))
),
ATTR_BINARY_SENSOR_VPN_STATE: int(float(response["uptime"])) > 0,
ATTR_SENSOR_VPN_UPTIME: 0,
ATTR_BINARY_SENSOR_VPN_STATE: False,
}

if "uptime" in response:
data |= {
ATTR_SENSOR_VPN_UPTIME: str(
timedelta(seconds=int(float(response["uptime"])))
),
ATTR_BINARY_SENSOR_VPN_STATE: int(float(response["uptime"])) > 0,
}

async def _async_prepare_rom_update(self, data: dict) -> None:
"""Prepare rom update.
Expand Down Expand Up @@ -1313,13 +1314,11 @@ def async_get_updater(hass: HomeAssistant, identifier: str) -> LuciUpdater:
if identifier in hass.data[DOMAIN] and UPDATER in hass.data[DOMAIN][identifier]:
return hass.data[DOMAIN][identifier][UPDATER]

integrations: list[LuciUpdater] = [
if integrations := [
integration[UPDATER]
for integration in hass.data[DOMAIN].values()
if isinstance(integration, dict) and integration[CONF_IP_ADDRESS] == identifier
]

if not integrations:
raise ValueError(_error)
]:
return integrations[0]

return integrations[0]
raise ValueError(_error)
2 changes: 1 addition & 1 deletion tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async def async_setup(
get_config_value(config_entry, CONF_TIMEOUT, DEFAULT_TIMEOUT),
get_config_value(config_entry, CONF_IS_FORCE_LOAD, is_force),
activity_days,
get_store(hass, _ip) if not without_store else None,
None if without_store else get_store(hass, _ip),
entry_id=config_entry.entry_id,
)

Expand Down
70 changes: 64 additions & 6 deletions tests/test_self_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,38 @@ async def test_supported(hass: HomeAssistant) -> None:

def pn_check(hass: HomeAssistant, message: str, title: str) -> None:
assert title == NAME
assert (
message
== 'Router 192.168.31.1 not supported.\n\nModel: R3600\n\nCheck list:\n * xqsystem/login: 🟒\n * xqsystem/init_info: 🟒\n * misystem/status: 🟒\n * xqnetwork/mode: 🟒\n * misystem/topo_graph: 🟒\n * xqsystem/check_rom_update: 🟒\n * xqnetwork/wan_info: 🟒\n * misystem/led: 🟒\n * xqnetwork/wifi_detail_all: 🟒\n * xqnetwork/wifi_diag_detail_all: 🟒\n * xqnetwork/avaliable_channels: 🟒\n * xqnetwork/wifi_connect_devices: 🟒\n * misystem/devicelist: 🟒\n * xqnetwork/wifiap_signal: 🟒\n * misystem/newstatus: 🟒\n * xqsystem/reboot: βšͺ\n * xqsystem/upgrade_rom: βšͺ\n * xqsystem/flash_permission: βšͺ\n * xqnetwork/set_wifi: βšͺ\n * xqnetwork/set_wifi_without_restart: βšͺ\n\n<a href="https://github.com/dmamontov/hass-miwifi/issues/new?title=Add+supports+R3600&body=Check+list%3A%0A+%2A+xqsystem%2Flogin%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Finit_info%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fstatus%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fmode%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Ftopo_graph%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Fcheck_rom_update%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwan_info%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fled%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_detail_all%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_diag_detail_all%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Favaliable_channels%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_connect_devices%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fdevicelist%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifiap_signal%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fnewstatus%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Freboot%3A+%E2%9A%AA%0A+%2A+xqsystem%2Fupgrade_rom%3A+%E2%9A%AA%0A+%2A+xqsystem%2Fflash_permission%3A+%E2%9A%AA%0A+%2A+xqnetwork%2Fset_wifi%3A+%E2%9A%AA%0A+%2A+xqnetwork%2Fset_wifi_without_restart%3A+%E2%9A%AA" target="_blank">Create an issue with the data from this post to add support</a>'
assert message == (
"Router 192.168.31.1 not supported.\n"
"\n"
"Model: R3600\n"
"\n"
"Check list:\n"
" * xqsystem/login: 🟒\n"
" * xqsystem/init_info: 🟒\n"
" * misystem/status: 🟒\n"
" * xqnetwork/mode: 🟒\n"
" * xqsystem/vpn_status: 🟒\n"
" * misystem/topo_graph: 🟒\n"
" * xqsystem/check_rom_update: 🟒\n"
" * xqnetwork/wan_info: 🟒\n"
" * misystem/led: 🟒\n"
" * xqnetwork/wifi_detail_all: 🟒\n"
" * xqnetwork/wifi_diag_detail_all: 🟒\n"
" * xqnetwork/avaliable_channels: 🟒\n"
" * xqnetwork/wifi_connect_devices: 🟒\n"
" * misystem/devicelist: 🟒\n"
" * xqnetwork/wifiap_signal: 🟒\n"
" * misystem/newstatus: 🟒\n"
" * xqsystem/reboot: βšͺ\n"
" * xqsystem/upgrade_rom: βšͺ\n"
" * xqsystem/flash_permission: βšͺ\n"
" * xqnetwork/set_wifi: βšͺ\n"
" * xqnetwork/set_wifi_without_restart: βšͺ\n"
"\n"
"<a "
'href="https://github.com/dmamontov/hass-miwifi/issues/new?title=Add+supports+R3600&body=Check+list%3A%0A+%2A+xqsystem%2Flogin%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Finit_info%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fstatus%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fmode%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Fvpn_status%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Ftopo_graph%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Fcheck_rom_update%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwan_info%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fled%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_detail_all%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_diag_detail_all%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Favaliable_channels%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_connect_devices%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fdevicelist%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifiap_signal%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fnewstatus%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Freboot%3A+%E2%9A%AA%0A+%2A+xqsystem%2Fupgrade_rom%3A+%E2%9A%AA%0A+%2A+xqsystem%2Fflash_permission%3A+%E2%9A%AA%0A+%2A+xqnetwork%2Fset_wifi%3A+%E2%9A%AA%0A+%2A+xqnetwork%2Fset_wifi_without_restart%3A+%E2%9A%AA" '
'target="_blank">Create an issue with the data from this post to add '
"support</a>"
)

with patch(
Expand Down Expand Up @@ -67,9 +96,38 @@ async def test_unsupported(hass: HomeAssistant) -> None:

def pn_check(hass: HomeAssistant, message: str, title: str) -> None:
assert title == "MiWifi"
assert (
message
== 'Router 192.168.31.1 not supported.\n\nModel: R3600\n\nCheck list:\n * xqsystem/login: 🟒\n * xqsystem/init_info: 🟒\n * misystem/status: 🟒\n * xqnetwork/mode: πŸ”΄\n * misystem/topo_graph: 🟒\n * xqsystem/check_rom_update: 🟒\n * xqnetwork/wan_info: 🟒\n * misystem/led: 🟒\n * xqnetwork/wifi_detail_all: 🟒\n * xqnetwork/wifi_diag_detail_all: 🟒\n * xqnetwork/avaliable_channels: 🟒\n * xqnetwork/wifi_connect_devices: 🟒\n * misystem/devicelist: 🟒\n * xqnetwork/wifiap_signal: 🟒\n * misystem/newstatus: 🟒\n * xqsystem/reboot: βšͺ\n * xqsystem/upgrade_rom: βšͺ\n * xqsystem/flash_permission: βšͺ\n * xqnetwork/set_wifi: βšͺ\n * xqnetwork/set_wifi_without_restart: βšͺ\n\n<a href="https://github.com/dmamontov/hass-miwifi/issues/new?title=Add+supports+R3600&body=Check+list%3A%0A+%2A+xqsystem%2Flogin%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Finit_info%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fstatus%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fmode%3A+%F0%9F%94%B4%0A+%2A+misystem%2Ftopo_graph%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Fcheck_rom_update%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwan_info%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fled%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_detail_all%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_diag_detail_all%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Favaliable_channels%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_connect_devices%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fdevicelist%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifiap_signal%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fnewstatus%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Freboot%3A+%E2%9A%AA%0A+%2A+xqsystem%2Fupgrade_rom%3A+%E2%9A%AA%0A+%2A+xqsystem%2Fflash_permission%3A+%E2%9A%AA%0A+%2A+xqnetwork%2Fset_wifi%3A+%E2%9A%AA%0A+%2A+xqnetwork%2Fset_wifi_without_restart%3A+%E2%9A%AA" target="_blank">Create an issue with the data from this post to add support</a>'
assert message == (
"Router 192.168.31.1 not supported.\n"
"\n"
"Model: R3600\n"
"\n"
"Check list:\n"
" * xqsystem/login: 🟒\n"
" * xqsystem/init_info: 🟒\n"
" * misystem/status: 🟒\n"
" * xqnetwork/mode: πŸ”΄\n"
" * xqsystem/vpn_status: 🟒\n"
" * misystem/topo_graph: 🟒\n"
" * xqsystem/check_rom_update: 🟒\n"
" * xqnetwork/wan_info: 🟒\n"
" * misystem/led: 🟒\n"
" * xqnetwork/wifi_detail_all: 🟒\n"
" * xqnetwork/wifi_diag_detail_all: 🟒\n"
" * xqnetwork/avaliable_channels: 🟒\n"
" * xqnetwork/wifi_connect_devices: 🟒\n"
" * misystem/devicelist: 🟒\n"
" * xqnetwork/wifiap_signal: 🟒\n"
" * misystem/newstatus: 🟒\n"
" * xqsystem/reboot: βšͺ\n"
" * xqsystem/upgrade_rom: βšͺ\n"
" * xqsystem/flash_permission: βšͺ\n"
" * xqnetwork/set_wifi: βšͺ\n"
" * xqnetwork/set_wifi_without_restart: βšͺ\n"
"\n"
"<a "
'href="https://github.com/dmamontov/hass-miwifi/issues/new?title=Add+supports+R3600&body=Check+list%3A%0A+%2A+xqsystem%2Flogin%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Finit_info%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fstatus%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fmode%3A+%F0%9F%94%B4%0A+%2A+xqsystem%2Fvpn_status%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Ftopo_graph%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Fcheck_rom_update%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwan_info%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fled%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_detail_all%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_diag_detail_all%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Favaliable_channels%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifi_connect_devices%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fdevicelist%3A+%F0%9F%9F%A2%0A+%2A+xqnetwork%2Fwifiap_signal%3A+%F0%9F%9F%A2%0A+%2A+misystem%2Fnewstatus%3A+%F0%9F%9F%A2%0A+%2A+xqsystem%2Freboot%3A+%E2%9A%AA%0A+%2A+xqsystem%2Fupgrade_rom%3A+%E2%9A%AA%0A+%2A+xqsystem%2Fflash_permission%3A+%E2%9A%AA%0A+%2A+xqnetwork%2Fset_wifi%3A+%E2%9A%AA%0A+%2A+xqnetwork%2Fset_wifi_without_restart%3A+%E2%9A%AA" '
'target="_blank">Create an issue with the data from this post to add '
"support</a>"
)

with patch(
Expand Down

0 comments on commit c983090

Please sign in to comment.