mirror of
https://github.com/home-assistant/core.git
synced 2025-05-17 20:39:16 +00:00

* Add config flow to Freebox * Add manufacturer in device_tracker info * Add device_info to sensor + switch * Add device_info: connections * Add config_flow test + update .coveragerc * Typing * Add device_type icon * Remove one error log * Fix pylint * Add myself as CODEOWNER * Handle sync in one place * Separate the Freebox[Router/Device/Sensor] from __init__.py * Add link step to config flow * Make temperature sensors auto-discovered * Use device activity instead of reachablility for device_tracker * Store token file in .storage Depending on host if list of Freebox integration on the future without breaking change * Remove IP sensors + add Freebox router as a device with attrs : IPs, conection type, uptime, version & serial * Add sensor should_poll=False * Test typing * Handle devices with no name * None is the default for data * Fix comment * Use config_entry.unique_id * Add async_unload_entry with asyncio * Add and use bunch of data size and rate related constants (#31781) * Review * Remove useless "already_configured" error string * Review : merge 2 device & 2 sensor classes * Entities from platforms * Fix unload + add device after setup + clean loggers * async_add_entities True * Review * Use pathlib + refactor get_api * device_tracker set + tests with CoroutineMock() * Removing active & reachable from tracker attrs * Review * Fix pipeline * typing * typing * typing * Raise ConfigEntryNotReady when HttpRequestError at setup * Review * Multiple Freebox s * Review: store sensors in router * Freebox: a sensor story
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
"""Support for Freebox Delta, Revolution and Mini 4K."""
|
|
import logging
|
|
from typing import Dict
|
|
|
|
from aiofreepybox.exceptions import InsufficientPermissionsError
|
|
|
|
from homeassistant.components.switch import SwitchDevice
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.helpers.typing import HomeAssistantType
|
|
|
|
from .const import DOMAIN
|
|
from .router import FreeboxRouter
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistantType, entry: ConfigEntry, async_add_entities
|
|
) -> None:
|
|
"""Set up the switch."""
|
|
router = hass.data[DOMAIN][entry.unique_id]
|
|
async_add_entities([FreeboxWifiSwitch(router)], True)
|
|
|
|
|
|
class FreeboxWifiSwitch(SwitchDevice):
|
|
"""Representation of a freebox wifi switch."""
|
|
|
|
def __init__(self, router: FreeboxRouter) -> None:
|
|
"""Initialize the Wifi switch."""
|
|
self._name = "Freebox WiFi"
|
|
self._state = None
|
|
self._router = router
|
|
self._unique_id = f"{self._router.mac} {self._name}"
|
|
|
|
@property
|
|
def unique_id(self) -> str:
|
|
"""Return a unique ID."""
|
|
return self._unique_id
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
"""Return the name of the switch."""
|
|
return self._name
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
"""Return true if device is on."""
|
|
return self._state
|
|
|
|
@property
|
|
def device_info(self) -> Dict[str, any]:
|
|
"""Return the device information."""
|
|
return self._router.device_info
|
|
|
|
async def _async_set_state(self, enabled: bool):
|
|
"""Turn the switch on or off."""
|
|
wifi_config = {"enabled": enabled}
|
|
try:
|
|
await self._router.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._router.wifi.get_global_config()
|
|
active = datas["enabled"]
|
|
self._state = bool(active)
|