1 """Support for Huawei LTE switches."""
3 from __future__
import annotations
9 DOMAIN
as SWITCH_DOMAIN,
20 KEY_DIALUP_MOBILE_DATASWITCH,
21 KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH,
23 from .entity
import HuaweiLteBaseEntityWithDevice
25 _LOGGER = logging.getLogger(__name__)
30 config_entry: ConfigEntry,
31 async_add_entities: AddEntitiesCallback,
33 """Set up from config entry."""
34 router = hass.data[DOMAIN].routers[config_entry.entry_id]
35 switches: list[Entity] = []
37 if router.data.get(KEY_DIALUP_MOBILE_DATASWITCH):
40 if router.data.get(KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH, {}).
get(
"WifiEnable"):
47 """Huawei LTE switch device base class."""
52 _attr_device_class: SwitchDeviceClass = SwitchDeviceClass.SWITCH
53 _raw_state: str |
None =
None
55 def _turn(self, state: bool) ->
None:
56 raise NotImplementedError
60 self.
_turn_turn(state=
True)
63 """Turn switch off."""
64 self.
_turn_turn(state=
False)
67 """Subscribe to needed data on add."""
69 self.
routerrouter.subscriptions[self.key].append(f
"{SWITCH_DOMAIN}/{self.item}")
72 """Unsubscribe from needed data on remove."""
74 self.
routerrouter.subscriptions[self.key].
remove(f
"{SWITCH_DOMAIN}/{self.item}")
79 value = self.
routerrouter.data[self.key][self.item]
81 _LOGGER.debug(
"%s[%s] not in data", self.key, self.item)
89 """Huawei LTE mobile data switch device."""
91 _attr_translation_key: str =
"mobile_data"
93 key = KEY_DIALUP_MOBILE_DATASWITCH
98 return f
"{self.key}.{self.item}"
102 """Return whether the switch is on."""
105 def _turn(self, state: bool) ->
None:
106 value = 1
if state
else 0
107 self.
routerrouter.client.dial_up.set_mobile_dataswitch(dataswitch=value)
113 """Huawei LTE WiFi guest network switch device."""
115 _attr_translation_key: str =
"wifi_guest_network"
117 key = KEY_WLAN_WIFI_GUEST_NETWORK_SWITCH
122 return f
"{self.key}.{self.item}"
126 """Return whether the switch is on."""
129 def _turn(self, state: bool) ->
None:
130 self.
routerrouter.client.wlan.wifi_guest_network_switch(state)
136 """Return the state attributes."""
137 return {
"ssid": self.
routerrouter.data[self.
keykey].
get(
"WifiSsid")}
None async_will_remove_from_hass(self)
None _turn(self, bool state)
None turn_on(self, **Any kwargs)
None async_added_to_hass(self)
None turn_off(self, **Any kwargs)
None _turn(self, bool state)
str _device_unique_id(self)
str _device_unique_id(self)
None _turn(self, bool state)
dict[str, str|None] extra_state_attributes(self)
None schedule_update_ha_state(self, bool force_refresh=False)
bool remove(self, _T matcher)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)