3 Get data from 'Usage Summary' page:
4 https://www.fido.ca/pages/#/my-account/wireless
7 from __future__
import annotations
9 from datetime
import timedelta
12 from pyfido
import FidoClient
13 from pyfido.client
import PyFidoError
14 import voluptuous
as vol
17 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
20 SensorEntityDescription,
23 CONF_MONITORED_VARIABLES,
37 _LOGGER = logging.getLogger(__name__)
47 SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
51 native_unit_of_measurement=PRICE,
57 native_unit_of_measurement=PRICE,
63 native_unit_of_measurement=UnitOfInformation.KILOBITS,
64 device_class=SensorDeviceClass.DATA_SIZE,
70 native_unit_of_measurement=UnitOfInformation.KILOBITS,
71 device_class=SensorDeviceClass.DATA_SIZE,
76 name=
"Data remaining",
77 native_unit_of_measurement=UnitOfInformation.KILOBITS,
78 device_class=SensorDeviceClass.DATA_SIZE,
84 native_unit_of_measurement=MESSAGES,
85 icon=
"mdi:message-text",
90 native_unit_of_measurement=MESSAGES,
91 icon=
"mdi:message-text",
95 name=
"Text remaining",
96 native_unit_of_measurement=MESSAGES,
97 icon=
"mdi:message-text",
102 native_unit_of_measurement=MESSAGES,
103 icon=
"mdi:message-image",
108 native_unit_of_measurement=MESSAGES,
109 icon=
"mdi:message-image",
113 name=
"MMS remaining",
114 native_unit_of_measurement=MESSAGES,
115 icon=
"mdi:message-image",
119 name=
"International text used",
120 native_unit_of_measurement=MESSAGES,
121 icon=
"mdi:message-alert",
124 key=
"text_int_limit",
125 name=
"International text limit",
126 native_unit_of_measurement=MESSAGES,
127 icon=
"mdi:message-alert",
130 key=
"text_int_remaining",
131 name=
"International remaining",
132 native_unit_of_measurement=MESSAGES,
133 icon=
"mdi:message-alert",
138 native_unit_of_measurement=UnitOfTime.MINUTES,
139 icon=
"mdi:cellphone",
144 native_unit_of_measurement=UnitOfTime.MINUTES,
145 icon=
"mdi:cellphone",
148 key=
"talk_remaining",
149 name=
"Talk remaining",
150 native_unit_of_measurement=UnitOfTime.MINUTES,
151 icon=
"mdi:cellphone",
154 key=
"other_talk_used",
155 name=
"Other Talk used",
156 native_unit_of_measurement=UnitOfTime.MINUTES,
157 icon=
"mdi:cellphone",
160 key=
"other_talk_limit",
161 name=
"Other Talk limit",
162 native_unit_of_measurement=UnitOfTime.MINUTES,
163 icon=
"mdi:cellphone",
166 key=
"other_talk_remaining",
167 name=
"Other Talk remaining",
168 native_unit_of_measurement=UnitOfTime.MINUTES,
169 icon=
"mdi:cellphone",
173 SENSOR_KEYS: list[str] = [desc.key
for desc
in SENSOR_TYPES]
175 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
177 vol.Required(CONF_MONITORED_VARIABLES): vol.All(
178 cv.ensure_list, [vol.In(SENSOR_KEYS)]
180 vol.Required(CONF_USERNAME): cv.string,
181 vol.Required(CONF_PASSWORD): cv.string,
182 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
190 async_add_entities: AddEntitiesCallback,
191 discovery_info: DiscoveryInfoType |
None =
None,
193 """Set up the Fido sensor."""
194 username = config[CONF_USERNAME]
195 password = config[CONF_PASSWORD]
198 fido_data =
FidoData(username, password, httpsession)
199 ret = await fido_data.async_update()
203 name = config[CONF_NAME]
204 monitored_variables = config[CONF_MONITORED_VARIABLES]
206 FidoSensor(fido_data, name, number, description)
207 for number
in fido_data.client.get_phone_numbers()
208 for description
in SENSOR_TYPES
209 if description.key
in monitored_variables
216 """Implementation of a Fido sensor."""
219 self, fido_data, name, number, description: SensorEntityDescription
221 """Initialize the sensor."""
226 self.
_attr_name_attr_name = f
"{name} {number} {description.name}"
230 """Return the state attributes of the sensor."""
231 return {
"number": self.
_number_number}
234 """Get the latest data from Fido and update the state."""
237 if self.
fido_datafido_data.data.get(sensor_type)
is not None:
239 elif self.
fido_datafido_data.data.get(self.
_number_number, {}).
get(sensor_type)
is not None:
246 """Get data from Fido."""
248 def __init__(self, username, password, httpsession):
249 """Initialize the data object."""
251 self.
clientclient = FidoClient(username, password, REQUESTS_TIMEOUT, httpsession)
254 @Throttle(MIN_TIME_BETWEEN_UPDATES)
256 """Get the latest data from Fido."""
260 except PyFidoError
as exp:
261 _LOGGER.error(
"Error on receive last Fido data: %s", exp)
def __init__(self, username, password, httpsession)
def extra_state_attributes(self)
None __init__(self, fido_data, name, number, SensorEntityDescription description)
web.Response get(self, web.Request request, str config_key)
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)