Add multi phone numbers support (#6605)
* Add multi phone numbers support * Update fido.pypull/6947/head
parent
f1f033e5d2
commit
118bd34d74
|
@ -21,7 +21,7 @@ from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ["pyfido==0.1.4"]
|
REQUIREMENTS = ["pyfido==1.0.1"]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -35,7 +35,6 @@ DEFAULT_NAME = "Fido"
|
||||||
REQUESTS_TIMEOUT = 15
|
REQUESTS_TIMEOUT = 15
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15)
|
||||||
|
|
||||||
|
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
'fido_dollar': ['Fido dollar',
|
'fido_dollar': ['Fido dollar',
|
||||||
PRICE, 'mdi:square-inc-cash'],
|
PRICE, 'mdi:square-inc-cash'],
|
||||||
|
@ -103,8 +102,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
for variable in config[CONF_MONITORED_VARIABLES]:
|
for number in fido_data.client.get_phone_numbers():
|
||||||
sensors.append(FidoSensor(fido_data, variable, name))
|
for variable in config[CONF_MONITORED_VARIABLES]:
|
||||||
|
sensors.append(FidoSensor(fido_data, variable, name, number))
|
||||||
|
|
||||||
add_devices(sensors, True)
|
add_devices(sensors, True)
|
||||||
|
|
||||||
|
@ -112,9 +112,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
class FidoSensor(Entity):
|
class FidoSensor(Entity):
|
||||||
"""Implementation of a Fido sensor."""
|
"""Implementation of a Fido sensor."""
|
||||||
|
|
||||||
def __init__(self, fido_data, sensor_type, name):
|
def __init__(self, fido_data, sensor_type, name, number):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.client_name = name
|
self.client_name = name
|
||||||
|
self._number = number
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
self._name = SENSOR_TYPES[sensor_type][0]
|
self._name = SENSOR_TYPES[sensor_type][0]
|
||||||
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
|
||||||
|
@ -125,7 +126,7 @@ class FidoSensor(Entity):
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return '{} {}'.format(self.client_name, self._name)
|
return '{} {} {}'.format(self.client_name, self._number, self._name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
@ -142,21 +143,33 @@ class FidoSensor(Entity):
|
||||||
"""Icon to use in the frontend, if any."""
|
"""Icon to use in the frontend, if any."""
|
||||||
return self._icon
|
return self._icon
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return the state attributes of the sensor."""
|
||||||
|
return {
|
||||||
|
'number': self._number,
|
||||||
|
}
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from Fido and update the state."""
|
"""Get the latest data from Fido and update the state."""
|
||||||
self.fido_data.update()
|
self.fido_data.update()
|
||||||
if self.type in self.fido_data.data:
|
if self._name == 'balance':
|
||||||
if self.fido_data.data[self.type] is not None:
|
if self.fido_data.data.get(self.type) is not None:
|
||||||
self._state = round(self.fido_data.data[self.type], 2)
|
self._state = round(self.fido_data.data[self.type], 2)
|
||||||
|
else:
|
||||||
|
if self.fido_data.data.get(self._number, {}).get(self.type) \
|
||||||
|
is not None:
|
||||||
|
self._state = self.fido_data.data[self._number][self.type]
|
||||||
|
self._state = round(self._state, 2)
|
||||||
|
|
||||||
|
|
||||||
class FidoData(object):
|
class FidoData(object):
|
||||||
"""Get data from Fido."""
|
"""Get data from Fido."""
|
||||||
|
|
||||||
def __init__(self, number, password):
|
def __init__(self, username, password):
|
||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
from pyfido import FidoClient
|
from pyfido import FidoClient
|
||||||
self.client = FidoClient(number, password, REQUESTS_TIMEOUT)
|
self.client = FidoClient(username, password, REQUESTS_TIMEOUT)
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
|
|
|
@ -515,7 +515,7 @@ pyemby==1.1
|
||||||
pyenvisalink==2.0
|
pyenvisalink==2.0
|
||||||
|
|
||||||
# homeassistant.components.sensor.fido
|
# homeassistant.components.sensor.fido
|
||||||
pyfido==0.1.4
|
pyfido==1.0.1
|
||||||
|
|
||||||
# homeassistant.components.ifttt
|
# homeassistant.components.ifttt
|
||||||
pyfttt==0.3
|
pyfttt==0.3
|
||||||
|
|
Loading…
Reference in New Issue