Skip to content

Commit 670f93a

Browse files
authoredJun 23, 2022
Merge pull request #84 from dmamontov/dev
Fix #78, #79, #80, #82, #83
2 parents 52ee6f7 + f5d56d4 commit 670f93a

17 files changed

+90
-5
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Many more Xiaomi and Redmi routers supported by MiWiFi
8484
| ![](images/RB03.png) | **Redmi Router AX6S** | RB03 | <sub>🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢</sub> |
8585
| ![](images/RB01.png) | **Xiaomi Router AX3200** | RB01 | <sub>🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢</sub> |
8686
| ![](images/RA81.png) | **Redmi Router AX3000** | RA81 | <sub>🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢</sub> |
87+
| ![](images/CR6606.png) | **Xiaomi China Unicom WiFi 6 Router** | CR6606 | <sub>🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢</sub> |
8788
| ![](images/RA71.png) | **Redmi Router AX1800** | RA71 | <sub>🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢</sub> |
8889
| ![](images/RA69.png) | **Redmi Router AX6** | RA69 | <sub>🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢</sub> |
8990
| ![](images/RA67.png) | **Redmi Router AX5** | RA67 | <sub>🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢🟢</sub> | <sub>🟢🟢🟢🟢🟢</sub> |

‎custom_components/miwifi/config_flow.py

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from .const import (
2323
CONF_ACTIVITY_DAYS,
24+
CONF_IS_TRACK_DEVICES,
2425
CONF_IS_FORCE_LOAD,
2526
CONF_STAY_ONLINE,
2627
CONF_ENCRYPTION_ALGORITHM,
@@ -136,6 +137,7 @@ async def async_step_user(
136137
EncryptionAlgorithm.SHA256,
137138
]
138139
),
140+
vol.Required(CONF_IS_TRACK_DEVICES, default=True): cv.boolean,
139141
vol.Required(
140142
CONF_STAY_ONLINE, default=DEFAULT_STAY_ONLINE
141143
): cv.positive_int,
@@ -223,6 +225,7 @@ async def async_step_discovery_confirm(
223225
EncryptionAlgorithm.SHA256,
224226
]
225227
),
228+
vol.Required(CONF_IS_TRACK_DEVICES, default=True): cv.boolean,
226229
vol.Required(
227230
CONF_STAY_ONLINE, default=DEFAULT_STAY_ONLINE
228231
): cv.positive_int,
@@ -337,6 +340,12 @@ def _get_options_schema(self) -> vol.Schema:
337340
EncryptionAlgorithm.SHA256,
338341
]
339342
),
343+
vol.Required(
344+
CONF_IS_TRACK_DEVICES,
345+
default=get_config_value(
346+
self._config_entry, CONF_IS_TRACK_DEVICES, True
347+
),
348+
): cv.boolean,
340349
vol.Required(
341350
CONF_STAY_ONLINE,
342351
default=get_config_value(

‎custom_components/miwifi/const.py

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
"""Custom conf"""
4343
CONF_STAY_ONLINE: Final = "stay_online"
44+
CONF_IS_TRACK_DEVICES: Final = "is_track_devices"
4445
CONF_IS_FORCE_LOAD: Final = "is_force_load"
4546
CONF_ACTIVITY_DAYS: Final = "activity_days"
4647
CONF_ENCRYPTION_ALGORITHM: Final = "encryption_algorithm"

‎custom_components/miwifi/device_tracker.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
ATTR_TRACKER_UP_SPEED,
4242
ATTR_TRACKER_UPDATER_ENTRY_ID,
4343
ATTRIBUTION,
44+
CONF_IS_TRACK_DEVICES,
4445
CONF_STAY_ONLINE,
4546
DEFAULT_CALL_DELAY,
4647
DEFAULT_STAY_ONLINE,
@@ -98,7 +99,10 @@ def add_device(new_device: dict) -> None:
9899
:param new_device: dict: Device object
99100
"""
100101

101-
if new_device[ATTR_TRACKER_UPDATER_ENTRY_ID] != config_entry.entry_id:
102+
if (
103+
not get_config_value(config_entry, CONF_IS_TRACK_DEVICES, True)
104+
or new_device[ATTR_TRACKER_UPDATER_ENTRY_ID] != config_entry.entry_id
105+
):
102106
return # pragma: no cover
103107

104108
entity_id: str = generate_entity_id(

‎custom_components/miwifi/enum.py

+1
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,4 @@ def __str__(self) -> str:
238238
RA72 = "ra72"
239239
RA70 = "ra70"
240240
RB04 = "rb04"
241+
CR6606 = "cr6606"

‎custom_components/miwifi/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "miwifi",
33
"name": "MiWiFi",
4-
"version": "2.7.5",
4+
"version": "2.8.0",
55
"documentation": "https://github.com/dmamontov/hass-miwifi/wiki",
66
"issue_tracker": "https://github.com/dmamontov/hass-miwifi/issues",
77
"config_flow": true,

‎custom_components/miwifi/strings.json

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"data": {
1414
"ip_address": "[%key:common::config_flow::data::ip_address%]",
1515
"password": "[%key:common::config_flow::data::password%]",
16+
"encryption_algorithm": "Password encryption algorithm",
17+
"is_track_devices": "Track devices",
1618
"stay_online": "Minimum stay online in seconds",
1719
"scan_interval": "Scan interval in seconds [PRO]",
1820
"timeout": "Timeout of requests in seconds [PRO]"
@@ -34,6 +36,8 @@
3436
"data": {
3537
"ip_address": "[%key:common::config_flow::data::ip_address%]",
3638
"password": "[%key:common::config_flow::data::password%]",
39+
"encryption_algorithm": "Password encryption algorithm",
40+
"is_track_devices": "Track devices",
3741
"stay_online": "Minimum stay online in seconds",
3842
"scan_interval": "Scan interval in seconds [PRO]",
3943
"activity_days": "Allowed number of days to wait after the last activity [PRO]",

‎custom_components/miwifi/switch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def _additional_prepare(self) -> bool:
326326
self._attr_entity_registry_enabled_default = False
327327
is_available = False
328328

329-
return is_available
329+
return is_available and self.entity_description.key in self._updater.data
330330

331331
def _change_icon(self, is_on: bool) -> None:
332332
"""Change icon

‎custom_components/miwifi/translations/de.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"ip_address": "IP Adresse",
1616
"password": "Passwort",
1717
"encryption_algorithm": "Passwort Verschlüsselungsalgorithmus",
18+
"is_track_devices": "Geräte verfolgen",
1819
"stay_online": "Mindestaufenthalt in Sekunden online",
1920
"scan_interval": "Scanintervall in Sekunden [PRO]",
2021
"timeout": "Timeout von Anfragen in Sekunden [PRO]"
@@ -37,6 +38,7 @@
3738
"ip_address": "IP Adresse",
3839
"password": "Passwort",
3940
"encryption_algorithm": "Passwort Verschlüsselungsalgorithmus",
41+
"is_track_devices": "Geräte verfolgen",
4042
"stay_online": "Mindestaufenthalt in Sekunden online",
4143
"scan_interval": "Scanintervall in Sekunden [PRO]",
4244
"activity_days": "Anzahl an Tagen, die nach der letzten Aktivität gewartet werden soll [PRO]",

‎custom_components/miwifi/translations/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"ip_address": "IP address",
1616
"password": "Password",
1717
"encryption_algorithm": "Password encryption algorithm",
18+
"is_track_devices": "Track devices",
1819
"stay_online": "Minimum stay online in seconds",
1920
"scan_interval": "Scan interval in seconds [PRO]",
2021
"timeout": "Timeout of requests in seconds [PRO]"
@@ -37,6 +38,7 @@
3738
"ip_address": "IP address",
3839
"password": "Password",
3940
"encryption_algorithm": "Password encryption algorithm",
41+
"is_track_devices": "Track devices",
4042
"stay_online": "Minimum stay online in seconds",
4143
"scan_interval": "Scan interval in seconds [PRO]",
4244
"activity_days": "Allowed number of days to wait after the last activity [PRO]",

‎custom_components/miwifi/translations/fr.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"ip_address": "Adresse IP",
1616
"password": "Mot de passe",
1717
"encryption_algorithm": "Algorithme de cryptage du mot de passe",
18+
"is_track_devices": "Suivre les appareils",
1819
"stay_online": "Reste en ligne minimum en secondes",
1920
"scan_interval": "Intervalle d'analyse en secondes [PRO]",
2021
"timeout": "Délai d'expiration des requêtes en secondes [PRO]"
@@ -37,6 +38,7 @@
3738
"ip_address": "Adresse IP",
3839
"password": "Mot de passe",
3940
"encryption_algorithm": "Algorithme de cryptage du mot de passe",
41+
"is_track_devices": "Suivre les appareils",
4042
"stay_online": "Reste en ligne minimum en secondes",
4143
"scan_interval": "Intervalle d'analyse en secondes [PRO]",
4244
"activity_days": "Nombre de jours d'attente autorisés après la dernière activité [PRO]",

‎custom_components/miwifi/translations/pt-BR.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"ip_address": "Endereço IP",
1616
"password": "Senha",
1717
"encryption_algorithm": "Algoritmo de criptografia de senha",
18+
"is_track_devices": "Dispositivos de rastreamento",
1819
"stay_online": "Estadia mínima online em segundos",
1920
"scan_interval": "Intervalo de varredura em segundos [PRO]",
2021
"timeout": "Tempo limite de solicitações em segundos [PRO]"
@@ -40,6 +41,7 @@
4041
"ip_address": "Endereço IP",
4142
"password": "Senha",
4243
"encryption_algorithm": "Algoritmo de criptografia de senha",
44+
"is_track_devices": "Dispositivos de rastreamento",
4345
"stay_online": "Estadia mínima online em segundos",
4446
"scan_interval": "Intervalo de varredura em segundos [PRO]",
4547
"activity_days": "Número permitido de dias de espera após a última atividade [PRO]",

‎custom_components/miwifi/translations/ru.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"ip_address": "IP адрес",
1616
"password": "Пароль",
1717
"encryption_algorithm": "Алгоритм шифрования пароля",
18+
"is_track_devices": "Отслеживать устройства",
1819
"stay_online": "Минимальное пребывание онлайн в секундах",
1920
"scan_interval": "Интервал сканирования в секундах [PRO]",
2021
"timeout": "Тайм-аут запросов в секундах [PRO]"
@@ -38,6 +39,7 @@
3839
"password": "Пароль",
3940
"encryption_algorithm": "Алгоритм шифрования пароля",
4041
"stay_online": "Минимальное пребывание онлайн в секундах",
42+
"is_track_devices": "Отслеживать устройства",
4143
"scan_interval": "Интервал сканирования в секундах [PRO]",
4244
"activity_days": "Допустимое количество дней ожидания после последней активности [PRO]",
4345
"timeout": "Тайм-аут запросов в секундах [PRO]",

‎custom_components/miwifi/translations/tr.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"ip_address": "IP adresi",
1616
"password": "Parola",
1717
"encryption_algorithm": "Şifreleme algoritması",
18+
"is_track_devices": "Cihazları takip edin",
1819
"stay_online": "En az çevrimiçi kalma süresi (saniye)",
1920
"scan_interval": "Tarama aralığı (saniye) [PRO]",
2021
"timeout": "İstek zaman aşımı (saniye) [PRO]"
@@ -37,6 +38,7 @@
3738
"ip_address": "IP adresi",
3839
"password": "Parola",
3940
"encryption_algorithm": "Şifreleme algoritması",
41+
"is_track_devices": "Cihazları takip edin",
4042
"stay_online": "En az çevrimiçi kalma süresi (saniye)",
4143
"scan_interval": "Tarama aralığı (saniye) [PRO]",
4244
"activity_days": "Son aktiviteden sonra beklenmesi gereken süre (gün) [PRO]",

‎custom_components/miwifi/updater.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,10 @@ async def _async_prepare_wifi(self, data: dict) -> None:
623623
:param data: dict
624624
"""
625625

626-
response: dict = await self.luci.wifi_detail_all()
626+
try:
627+
response: dict = await self.luci.wifi_detail_all()
628+
except LuciError:
629+
return
627630

628631
if "bsd" in response:
629632
data[ATTR_BINARY_SENSOR_DUAL_BAND] = int(response["bsd"]) == 1

‎images/CR6606.png

6.86 KB
Loading

‎tests/test_switch.py

+51-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
DOMAIN,
4040
UPDATER,
4141
)
42-
from custom_components.miwifi.exceptions import LuciRequestError
42+
from custom_components.miwifi.exceptions import LuciConnectionError, LuciRequestError
4343
from custom_components.miwifi.helper import generate_entity_id
4444
from custom_components.miwifi.updater import LuciUpdater
4545
from tests.setup import MultipleSideEffect, async_mock_luci_client, async_setup
@@ -218,6 +218,56 @@ async def test_init_without_guest(hass: HomeAssistant) -> None:
218218
assert registry.async_get(unique_id) is None
219219

220220

221+
async def test_init_with_error(hass: HomeAssistant) -> None:
222+
"""Test init.
223+
224+
:param hass: HomeAssistant
225+
"""
226+
227+
with patch(
228+
"custom_components.miwifi.updater.LuciClient"
229+
) as mock_luci_client, patch(
230+
"custom_components.miwifi.updater.async_dispatcher_send"
231+
), patch(
232+
"custom_components.miwifi.async_start_discovery", return_value=None
233+
), patch(
234+
"custom_components.miwifi.device_tracker.socket.socket"
235+
) as mock_socket, patch(
236+
"custom_components.miwifi.updater.asyncio.sleep", return_value=None
237+
):
238+
mock_socket.return_value.recv.return_value = AsyncMock(return_value=None)
239+
240+
await async_mock_luci_client(mock_luci_client)
241+
242+
mock_luci_client.return_value.wifi_detail_all = AsyncMock(
243+
side_effect=LuciConnectionError
244+
)
245+
246+
setup_data: list = await async_setup(hass)
247+
248+
config_entry: MockConfigEntry = setup_data[1]
249+
250+
assert await hass.config_entries.async_setup(config_entry.entry_id)
251+
await hass.async_block_till_done()
252+
253+
updater: LuciUpdater = hass.data[DOMAIN][config_entry.entry_id][UPDATER]
254+
registry = er.async_get(hass)
255+
256+
assert updater.last_update_success
257+
258+
unique_id: str = _generate_id(ATTR_SWITCH_WIFI_2_4_NAME, updater)
259+
states: State | None = hass.states.get(unique_id)
260+
assert states is not None
261+
assert states.state == STATE_UNAVAILABLE
262+
assert registry.async_get(unique_id) is not None
263+
264+
unique_id = _generate_id(ATTR_SWITCH_WIFI_5_0_NAME, updater)
265+
states = hass.states.get(unique_id)
266+
assert states is not None
267+
assert states.state == STATE_UNAVAILABLE
268+
assert registry.async_get(unique_id) is not None
269+
270+
221271
async def test_init_bsd(
222272
hass: HomeAssistant,
223273
) -> None:

0 commit comments

Comments
 (0)
Please sign in to comment.