8000 Add multi phone numbers support by titilambert · Pull Request #6605 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add multi phone numbers support #6605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions homeassistant/components/sensor/fido.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ["pyfido==0.1.4"]
REQUIREMENTS = ["pyfido==1.0.1"]

_LOGGER = logging.getLogger(__name__)

Expand All @@ -35,7 +35,6 @@
REQUESTS_TIMEOUT = 15
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15)


SENSOR_TYPES = {
'fido_dollar': ['Fido dollar',
PRICE, 'mdi:square-inc-cash'],
Expand Down Expand Up @@ -103,18 +102,20 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
name = config.get(CONF_NAME)

sensors = []
for variable in config[CONF_MONITORED_VARIABLES]:
sensors.append(FidoSensor(fido_data, variable, name))
for number in fido_data.client.get_phone_numbers():
for variable in config[CONF_MONITORED_VARIABLES]:
sensors.append(FidoSensor(fido_data, variable, name, number))

add_devices(sensors, True)


class FidoSensor(Entity):
"""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."""
self.client_name = name
self._number = number
self.type = sensor_type
self._name = SENSOR_TYPES[sensor_type][0]
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
Expand All @@ -125,7 +126,7 @@ def __init__(self, fido_data, sensor_type, name):
@property
def name(self):
"""Return the name of the sensor."""
return '{} {}'.format(self.client_name, self._name)
return '{} {} {}'.format(self.client_name, self._number, self._name)

@property
def state(self):
Expand All @@ -142,21 +143,33 @@ def icon(self):
"""Icon to use in the frontend, if any."""
return self._icon

@property
def device_state_attributes(self):
"""Return the state attributes of the sensor."""
return {
'number': self._number,
}

def update(self):
"""Get the latest data from Fido and update the state."""
self.fido_data.update()
if self.type in self.fido_data.data:
if self.fido_data.data[self.type] is not None:
if self._name == 'balance':
if self.fido_data.data.get(self.type) is not None:
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):
"""Get data from Fido."""

def __init__(self, number, password):
def __init__(self, username, password):
"""Initialize the data object."""
from pyfido import FidoClient
self.client = FidoClient(number, password, REQUESTS_TIMEOUT)
self.client = FidoClient(username, password, REQUESTS_TIMEOUT)
self.data = {}

@Throttle(MIN_TIME_BETWEEN_UPDATES)
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ pyemby==1.1
pyenvisalink==2.0

# homeassistant.components.sensor.fido
pyfido==0.1.4
pyfido==1.0.1

# homeassistant.components.ifttt
pyfttt==0.3
Expand Down
0