Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Mamontov committed Apr 4, 2022
1 parent 36518ac commit 6d110fa
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 141 deletions.
2 changes: 1 addition & 1 deletion custom_components/miwifi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:


async def async_remove_config_entry_device(
hass: HomeAssistant, entry: ConfigEntry, device_entry: dr.DeviceEntry
hass: HomeAssistant, entry: ConfigEntry, device_entry: dr.DeviceEntry
) -> bool:
"""Remove cast config entry from a device.
Expand Down
16 changes: 8 additions & 8 deletions custom_components/miwifi/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up MiWifi binary sensor entry.
Expand All @@ -92,7 +92,7 @@ async def async_setup_entry(

entities: list[MiWifiBinarySensor] = [
MiWifiBinarySensor(
f"{config_entry.unique_id}-{description.key}",
f"{config_entry.entry_id}-{description.key}",
description,
updater,
)
Expand All @@ -107,10 +107,10 @@ class MiWifiBinarySensor(BinarySensorEntity, CoordinatorEntity, RestoreEntity):
_attr_attribution: str = ATTRIBUTION

def __init__(
self,
unique_id: str,
description: BinarySensorEntityDescription,
updater: LuciUpdater,
self,
unique_id: str,
description: BinarySensorEntityDescription,
updater: LuciUpdater,
) -> None:
"""Initialize sensor.
Expand Down
16 changes: 8 additions & 8 deletions custom_components/miwifi/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up MiWifi button entry.
Expand All @@ -64,7 +64,7 @@ async def async_setup_entry(

entities: list[MiWifiButton] = [
MiWifiButton(
f"{config_entry.unique_id}-{description.key}",
f"{config_entry.entry_id}-{description.key}",
description,
updater,
)
Expand All @@ -79,10 +79,10 @@ class MiWifiButton(ButtonEntity, CoordinatorEntity, RestoreEntity):
_attr_attribution: str = ATTRIBUTION

def __init__(
self,
unique_id: str,
description: ButtonEntityDescription,
updater: LuciUpdater,
self,
unique_id: str,
description: ButtonEntityDescription,
updater: LuciUpdater,
) -> None:
"""Initialize button.
Expand Down
16 changes: 8 additions & 8 deletions custom_components/miwifi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MiWifiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
@staticmethod
@callback
def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
config_entry: config_entries.ConfigEntry,
) -> MiWifiOptionsFlow:
"""Get the options flow for this handler.
Expand Down Expand Up @@ -89,7 +89,7 @@ async def _async_discovery_handoff(self) -> FlowResult:
return self.async_abort(reason="discovery_started")

async def async_step_integration_discovery(
self, discovery_info: DiscoveryInfoType
self, discovery_info: DiscoveryInfoType
) -> FlowResult:
"""Handle discovery via integration.
Expand All @@ -105,7 +105,7 @@ async def async_step_integration_discovery(
return await self.async_step_discovery_confirm()

async def async_step_user(
self, user_input: ConfigType | None = None, errors: dict[str, str] | None = None
self, user_input: ConfigType | None = None, errors: dict[str, str] | None = None
) -> FlowResult:
"""Handle a flow initialized by the user.
Expand All @@ -132,7 +132,7 @@ async def async_step_user(
)

async def async_step_discovery_confirm(
self, user_input: ConfigType | None = None
self, user_input: ConfigType | None = None
) -> FlowResult:
"""Handle a flow initialized by discovery.
Expand Down Expand Up @@ -268,10 +268,10 @@ def _get_options_schema(self) -> vol.Schema:
}

if (
DOMAIN not in self.hass.data
or self._config_entry.entry_id not in self.hass.data[DOMAIN]
or UPDATER not in self.hass.data[DOMAIN][self._config_entry.entry_id]
or self.hass.data[DOMAIN][self._config_entry.entry_id][UPDATER].is_repeater
DOMAIN not in self.hass.data
or self._config_entry.entry_id not in self.hass.data[DOMAIN]
or UPDATER not in self.hass.data[DOMAIN][self._config_entry.entry_id]
or self.hass.data[DOMAIN][self._config_entry.entry_id][UPDATER].is_repeater
):
schema |= {
vol.Optional(
Expand Down
22 changes: 11 additions & 11 deletions custom_components/miwifi/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up MiWifi device tracker entry.
Expand Down Expand Up @@ -108,10 +108,10 @@ class MiWifiDeviceTracker(ScannerEntity, CoordinatorEntity):
_device: dict

def __init__(
self,
unique_id: str,
device: dict,
updater: LuciUpdater,
self,
unique_id: str,
device: dict,
updater: LuciUpdater,
) -> None:
"""Initialize device_tracker.
Expand Down Expand Up @@ -150,7 +150,7 @@ def mac_address(self) -> str | None:

return self._device.get(ATTR_TRACKER_MAC, None)

@cached_property
@property
def manufacturer(self) -> str | None:
"""Return manufacturer of the device.
Expand Down Expand Up @@ -325,9 +325,9 @@ def _handle_coordinator_update(self) -> None:
break

if (
self._attr_available == is_available
and self._is_connected == is_connected
and not is_update
self._attr_available == is_available
and self._is_connected == is_connected
and not is_update
):
return

Expand Down
6 changes: 3 additions & 3 deletions custom_components/miwifi/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ async def async_discover_devices(client: AsyncClient) -> list:

@callback
def async_trigger_discovery(
hass: HomeAssistant,
discovered_devices: list,
hass: HomeAssistant,
discovered_devices: list,
) -> None:
"""Trigger config flows for discovered devices.
Expand All @@ -109,7 +109,7 @@ def parse_leafs(devices: list, leafs: list) -> list:
"""

for leaf in leafs:
if "ip" not in leaf:
if "ip" not in leaf or len(leaf["ip"]) == 0:
continue

devices.append(leaf["ip"])
Expand Down
2 changes: 1 addition & 1 deletion custom_components/miwifi/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def get_config_value(
config_entry: config_entries.ConfigEntry | None, param: str, default=None
config_entry: config_entries.ConfigEntry | None, param: str, default=None
) -> Any:
"""Get current value for configuration parameter.
Expand Down
16 changes: 8 additions & 8 deletions custom_components/miwifi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up MiWifi light entry.
Expand All @@ -71,7 +71,7 @@ async def async_setup_entry(

entities: list[MiWifiLight] = [
MiWifiLight(
f"{config_entry.unique_id}-{description.key}",
f"{config_entry.entry_id}-{description.key}",
description,
updater,
)
Expand All @@ -86,10 +86,10 @@ class MiWifiLight(LightEntity, CoordinatorEntity, RestoreEntity):
_attr_attribution: str = ATTRIBUTION

def __init__(
self,
unique_id: str,
description: LightEntityDescription,
updater: LuciUpdater,
self,
unique_id: str,
description: LightEntityDescription,
updater: LuciUpdater,
) -> None:
"""Initialize light.
Expand Down
12 changes: 6 additions & 6 deletions custom_components/miwifi/luci.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class LuciClient(object):
_url: str

def __init__(
self,
client: AsyncClient,
ip: str = CLIENT_ADDRESS,
password: str | None = None,
timeout: int = DEFAULT_TIMEOUT,
self,
client: AsyncClient,
ip: str = CLIENT_ADDRESS,
password: str | None = None,
timeout: int = DEFAULT_TIMEOUT,
) -> None:
"""Initialize API client.
Expand Down Expand Up @@ -279,7 +279,7 @@ def get_mac_address() -> str:

as_hex: str = f"{uuid.getnode():012x}"

return ":".join(as_hex[i: i + 2] for i in range(0, 12, 2))
return ":".join(as_hex[i : i + 2] for i in range(0, 12, 2))

def generate_nonce(self) -> str:
"""Generate fake nonce.
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.0.0",
"version": "2.0.1",
"documentation": "https://github.com/dmamontov/hass-miwifi",
"issue_tracker": "https://github.com/dmamontov/hass-miwifi/issues",
"config_flow": true,
Expand Down
26 changes: 9 additions & 17 deletions custom_components/miwifi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_SENSOR_DEVICES_GUEST,
name=ATTR_SENSOR_DEVICES_GUEST_NAME,
icon="mdi:counter",
native_unit_of_measurement=PCS,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key=ATTR_SENSOR_DEVICES_2_4,
name=ATTR_SENSOR_DEVICES_2_4_NAME,
Expand Down Expand Up @@ -158,9 +150,9 @@


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up MiWifi sensor entry.
Expand All @@ -177,13 +169,13 @@ async def async_setup_entry(

entities: list[MiWifiSensor] = [
MiWifiSensor(
f"{config_entry.unique_id}-{description.key}",
f"{config_entry.entry_id}-{description.key}",
description,
updater,
)
for description in MIWIFI_SENSORS
if description.key != ATTR_SENSOR_DEVICES_5_0_GAME
or updater.data.get(ATTR_WIFI_ADAPTER_LENGTH, 3) == 3
or updater.data.get(ATTR_WIFI_ADAPTER_LENGTH, 3) == 3
]
async_add_entities(entities)

Expand All @@ -194,10 +186,10 @@ class MiWifiSensor(SensorEntity, CoordinatorEntity, RestoreEntity):
_attr_attribution: str = ATTRIBUTION

def __init__(
self,
unique_id: str,
description: SensorEntityDescription,
updater: LuciUpdater,
self,
unique_id: str,
description: SensorEntityDescription,
updater: LuciUpdater,
) -> None:
"""Initialize sensor.
Expand Down
18 changes: 9 additions & 9 deletions custom_components/miwifi/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up MiWifi switch entry.
Expand All @@ -96,13 +96,13 @@ async def async_setup_entry(

entities: list[MiWifiSwitch] = [
MiWifiSwitch(
f"{config_entry.unique_id}-{description.key}",
f"{config_entry.entry_id}-{description.key}",
description,
updater,
)
for description in MIWIFI_SWITCHES
if description.key != ATTR_SWITCH_WIFI_5_0_GAME
or updater.data.get(ATTR_WIFI_ADAPTER_LENGTH, 3) == 3
or updater.data.get(ATTR_WIFI_ADAPTER_LENGTH, 3) == 3
]
async_add_entities(entities)

Expand All @@ -113,10 +113,10 @@ class MiWifiSwitch(SwitchEntity, CoordinatorEntity, RestoreEntity):
_attr_attribution: str = ATTRIBUTION

def __init__(
self,
unique_id: str,
description: SwitchEntityDescription,
updater: LuciUpdater,
self,
unique_id: str,
description: SwitchEntityDescription,
updater: LuciUpdater,
) -> None:
"""Initialize switch.
Expand Down
Loading

0 comments on commit 6d110fa

Please sign in to comment.