Add call direction sensor for Obihai (#26867)

* Add call direction sensor for obihai

* Check user credentials

* Review comments

* Fix return
pull/26916/head
Daniel Shokouhi 2019-09-25 11:26:15 -07:00 committed by Martin Hjelmare
parent d1adb28c6b
commit 36f604f79d
3 changed files with 19 additions and 2 deletions

View File

@ -3,7 +3,7 @@
"name": "Obihai",
"documentation": "https://www.home-assistant.io/components/obihai",
"requirements": [
"pyobihai==1.1.0"
"pyobihai==1.1.1"
],
"dependencies": [],
"codeowners": ["@dshokouhi"]

View File

@ -46,16 +46,26 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
pyobihai = PyObihai()
login = pyobihai.check_account(host, username, password)
if not login:
_LOGGER.error("Invalid credentials")
return
services = pyobihai.get_state(host, username, password)
line_services = pyobihai.get_line_state(host, username, password)
call_direction = pyobihai.get_call_direction(host, username, password)
for key in services:
sensors.append(ObihaiServiceSensors(pyobihai, host, username, password, key))
for key in line_services:
sensors.append(ObihaiServiceSensors(pyobihai, host, username, password, key))
for key in call_direction:
sensors.append(ObihaiServiceSensors(pyobihai, host, username, password, key))
add_entities(sensors)
@ -102,3 +112,10 @@ class ObihaiServiceSensors(Entity):
if self._service_name in services:
self._state = services.get(self._service_name)
call_direction = self._pyobihai.get_call_direction(
self._host, self._username, self._password
)
if self._service_name in call_direction:
self._state = call_direction.get(self._service_name)

View File

@ -1346,7 +1346,7 @@ pynx584==0.4
pynzbgetapi==0.2.0
# homeassistant.components.obihai
pyobihai==1.1.0
pyobihai==1.1.1
# homeassistant.components.ombi
pyombi==0.1.5