2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Freebox devices (Freebox v6 and Freebox mini 4K)."""
|
2018-12-27 23:26:09 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DATA_FREEBOX
|
|
|
|
|
2018-12-27 23:26:09 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2018-12-27 23:26:09 +00:00
|
|
|
"""Set up the sensors."""
|
|
|
|
fbx = hass.data[DATA_FREEBOX]
|
2019-02-13 20:21:14 +00:00
|
|
|
async_add_entities([FbxRXSensor(fbx), FbxTXSensor(fbx)], True)
|
2018-12-27 23:26:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FbxSensor(Entity):
|
|
|
|
"""Representation of a freebox sensor."""
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
_name = "generic"
|
2019-12-23 16:37:41 +00:00
|
|
|
_unit = None
|
|
|
|
_icon = None
|
2018-12-27 23:26:09 +00:00
|
|
|
|
|
|
|
def __init__(self, fbx):
|
|
|
|
"""Initialize the sensor."""
|
|
|
|
self._fbx = fbx
|
|
|
|
self._state = None
|
|
|
|
self._datas = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._name
|
|
|
|
|
2019-12-23 16:37:41 +00:00
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit of the sensor."""
|
|
|
|
return self._unit
|
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the icon of the sensor."""
|
|
|
|
return self._icon
|
|
|
|
|
2018-12-27 23:26:09 +00:00
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the sensor."""
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
async def async_update(self):
|
|
|
|
"""Fetch status from freebox."""
|
|
|
|
self._datas = await self._fbx.connection.get_status()
|
|
|
|
|
|
|
|
|
|
|
|
class FbxRXSensor(FbxSensor):
|
|
|
|
"""Update the Freebox RxSensor."""
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
_name = "Freebox download speed"
|
|
|
|
_unit = "KB/s"
|
2019-12-23 16:37:41 +00:00
|
|
|
_icon = "mdi:download-network"
|
2018-12-27 23:26:09 +00:00
|
|
|
|
|
|
|
async def async_update(self):
|
|
|
|
"""Get the value from fetched datas."""
|
|
|
|
await super().async_update()
|
|
|
|
if self._datas is not None:
|
2019-07-31 19:25:30 +00:00
|
|
|
self._state = round(self._datas["rate_down"] / 1000, 2)
|
2018-12-27 23:26:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FbxTXSensor(FbxSensor):
|
|
|
|
"""Update the Freebox TxSensor."""
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
_name = "Freebox upload speed"
|
|
|
|
_unit = "KB/s"
|
2019-12-23 16:37:41 +00:00
|
|
|
_icon = "mdi:upload-network"
|
2018-12-27 23:26:09 +00:00
|
|
|
|
|
|
|
async def async_update(self):
|
|
|
|
"""Get the value from fetched datas."""
|
|
|
|
await super().async_update()
|
|
|
|
if self._datas is not None:
|
2019-07-31 19:25:30 +00:00
|
|
|
self._state = round(self._datas["rate_up"] / 1000, 2)
|