Skip to content

Commit

Permalink
fix dual band
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Mamontov committed Apr 4, 2022
1 parent 6d110fa commit b688743
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions custom_components/miwifi/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __init__(

self._attr_is_on = updater.data.get(description.key, False)

self._additional_prepare()
self._attr_available = self._additional_prepare()

async def async_added_to_hass(self) -> None:
"""When entity is added to hass."""
Expand All @@ -163,10 +163,9 @@ async def async_added_to_hass(self) -> None:
def _handle_coordinator_update(self) -> None:
"""Update state."""

is_available: bool = self._updater.data.get(ATTR_STATE, False)
is_on: bool = self._updater.data.get(self.entity_description.key, False)

self._additional_prepare()
is_available: bool = self._additional_prepare()

if self._attr_is_on == is_on and self._attr_available == is_available:
return
Expand Down Expand Up @@ -288,16 +287,23 @@ async def _async_call(self, method: str, state: str, **kwargs: Any) -> None:

self._updater.data[self.entity_description.key] = state == STATE_ON

def _additional_prepare(self) -> None:
"""Prepare wifi switch"""
def _additional_prepare(self) -> bool:
"""Prepare wifi switch
reuturn bool: is_available
"""

is_available: bool = self._updater.data.get(ATTR_STATE, False)

if self._updater.data.get(ATTR_BINARY_SENSOR_DUAL_BAND, False):
if self.entity_description.key in [
ATTR_SWITCH_WIFI_5_0,
ATTR_SWITCH_WIFI_5_0_GAME,
]:
self._attr_entity_registry_enabled_default = False
self._attr_available = False
is_available = False

if self.entity_description.key == ATTR_SWITCH_WIFI_2_4:
self._attr_name = ATTR_WIFI_NAME

return is_available

0 comments on commit b688743

Please sign in to comment.