1
mirror of https://github.com/home-assistant/core synced 2024-09-03 08:14:07 +02:00
ha-core/homeassistant/components/freebox/switch.py
Christian Clauss df7d2b3aeb
Fix typos found by codespell (#31243)
* Fix typos found by codespell

* Fix typos found by codespell

* codespell: Furture  ==> Future

* Update test_config_flow.py

* Update __init__.py

* Spellcheck: successfull  ==> successful

* Codespell: unsuccesful  ==> unsuccessful

* Codespell: cant  ==> can't

* Codespell: firware ==> firmware

* Codespell: mimick  ==> mimic
2020-01-31 08:33:00 -08:00

63 lines
1.8 KiB
Python

"""Support for Freebox Delta, Revolution and Mini 4K."""
import logging
from homeassistant.components.switch import SwitchDevice
from . import DATA_FREEBOX
_LOGGER = logging.getLogger(__name__)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the switch."""
fbx = hass.data[DATA_FREEBOX]
async_add_entities([FbxWifiSwitch(fbx)], True)
class FbxWifiSwitch(SwitchDevice):
"""Representation of a freebox wifi switch."""
def __init__(self, fbx):
"""Initialize the Wifi switch."""
self._name = "Freebox WiFi"
self._state = None
self._fbx = fbx
@property
def name(self):
"""Return the name of the switch."""
return self._name
@property
def is_on(self):
"""Return true if device is on."""
return self._state
async def _async_set_state(self, enabled):
"""Turn the switch on or off."""
from aiofreepybox.exceptions import InsufficientPermissionsError
wifi_config = {"enabled": enabled}
try:
await self._fbx.wifi.set_global_config(wifi_config)
except InsufficientPermissionsError:
_LOGGER.warning(
"Home Assistant does not have permissions to"
" modify the Freebox settings. Please refer"
" to documentation."
)
async def async_turn_on(self, **kwargs):
"""Turn the switch on."""
await self._async_set_state(True)
async def async_turn_off(self, **kwargs):
"""Turn the switch off."""
await self._async_set_state(False)
async def async_update(self):
"""Get the state and update it."""
datas = await self._fbx.wifi.get_global_config()
active = datas["enabled"]
self._state = bool(active)