3 Get data from 'My Usage Page' page: https://client.ebox.ca/myusage
6 from __future__
import annotations
8 from datetime
import timedelta
11 from pyebox
import EboxClient
12 from pyebox.client
import PyEboxError
13 import voluptuous
as vol
16 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
19 SensorEntityDescription,
22 CONF_MONITORED_VARIABLES,
38 _LOGGER = logging.getLogger(__name__)
49 SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
53 native_unit_of_measurement=PERCENTAGE,
59 native_unit_of_measurement=PRICE,
65 native_unit_of_measurement=UnitOfInformation.GIGABITS,
66 device_class=SensorDeviceClass.DATA_SIZE,
72 native_unit_of_measurement=UnitOfTime.DAYS,
73 icon=
"mdi:calendar-today",
76 key=
"before_offpeak_download",
77 name=
"Download before offpeak",
78 native_unit_of_measurement=UnitOfInformation.GIGABITS,
79 device_class=SensorDeviceClass.DATA_SIZE,
83 key=
"before_offpeak_upload",
84 name=
"Upload before offpeak",
85 native_unit_of_measurement=UnitOfInformation.GIGABITS,
86 device_class=SensorDeviceClass.DATA_SIZE,
90 key=
"before_offpeak_total",
91 name=
"Total before offpeak",
92 native_unit_of_measurement=UnitOfInformation.GIGABITS,
93 device_class=SensorDeviceClass.DATA_SIZE,
97 key=
"offpeak_download",
98 name=
"Offpeak download",
99 native_unit_of_measurement=UnitOfInformation.GIGABITS,
100 device_class=SensorDeviceClass.DATA_SIZE,
104 key=
"offpeak_upload",
105 name=
"Offpeak Upload",
106 native_unit_of_measurement=UnitOfInformation.GIGABITS,
107 device_class=SensorDeviceClass.DATA_SIZE,
112 name=
"Offpeak Total",
113 native_unit_of_measurement=UnitOfInformation.GIGABITS,
114 device_class=SensorDeviceClass.DATA_SIZE,
120 native_unit_of_measurement=UnitOfInformation.GIGABITS,
121 device_class=SensorDeviceClass.DATA_SIZE,
127 native_unit_of_measurement=UnitOfInformation.GIGABITS,
128 device_class=SensorDeviceClass.DATA_SIZE,
134 native_unit_of_measurement=UnitOfInformation.GIGABITS,
135 device_class=SensorDeviceClass.DATA_SIZE,
140 SENSOR_TYPE_KEYS: list[str] = [desc.key
for desc
in SENSOR_TYPES]
142 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
144 vol.Required(CONF_MONITORED_VARIABLES): vol.All(
145 cv.ensure_list, [vol.In(SENSOR_TYPE_KEYS)]
147 vol.Required(CONF_USERNAME): cv.string,
148 vol.Required(CONF_PASSWORD): cv.string,
149 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
157 async_add_entities: AddEntitiesCallback,
158 discovery_info: DiscoveryInfoType |
None =
None,
160 """Set up the EBox sensor."""
161 username = config.get(CONF_USERNAME)
162 password = config.get(CONF_PASSWORD)
165 ebox_data =
EBoxData(username, password, httpsession)
167 name = config.get(CONF_NAME)
170 await ebox_data.async_update()
171 except PyEboxError
as exp:
172 _LOGGER.error(
"Failed login: %s", exp)
173 raise PlatformNotReady
from exp
177 for description
in SENSOR_TYPES
178 if description.key
in config[CONF_MONITORED_VARIABLES]
185 """Implementation of a EBox sensor."""
190 description: SensorEntityDescription,
193 """Initialize the sensor."""
199 """Get the latest data from EBox and update the state."""
208 """Get data from Ebox."""
210 def __init__(self, username, password, httpsession):
211 """Initialize the data object."""
212 self.
clientclient = EboxClient(username, password, REQUESTS_TIMEOUT, httpsession)
215 @Throttle(MIN_TIME_BETWEEN_UPDATES)
217 """Get the latest data from Ebox."""
220 except PyEboxError
as exp:
221 _LOGGER.error(
"Error on receive last EBox data: %s", exp)
def __init__(self, username, password, httpsession)
None __init__(self, ebox_data, SensorEntityDescription description, name)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
MetOfficeData fetch_data(datapoint.Manager connection, Site site, str mode)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)