Skip to content
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
2 changes: 1 addition & 1 deletion homeassistant/components/obihai/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Obihai",
"documentation": "https://www.home-assistant.io/components/obihai",
"requirements": [
"pyobihai==1.1.1"
"pyobihai==1.2.0"
],
"dependencies": [],
"codeowners": ["@dshokouhi"]
Expand Down
46 changes: 27 additions & 19 deletions homeassistant/components/obihai/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,43 @@ def setup_platform(hass, config, add_entities, discovery_info=None):

sensors = []

pyobihai = PyObihai()
pyobihai = PyObihai(host, username, password)

login = pyobihai.check_account(host, username, password)
login = pyobihai.check_account()
if not login:
_LOGGER.error("Invalid credentials")
return

services = pyobihai.get_state(host, username, password)
serial = pyobihai.get_device_serial()

line_services = pyobihai.get_line_state(host, username, password)
services = pyobihai.get_state()

call_direction = pyobihai.get_call_direction(host, username, password)
line_services = pyobihai.get_line_state()

call_direction = pyobihai.get_call_direction()

for key in services:
sensors.append(ObihaiServiceSensors(pyobihai, host, username, password, key))
sensors.append(ObihaiServiceSensors(pyobihai, serial, key))

for key in line_services:
sensors.append(ObihaiServiceSensors(pyobihai, host, username, password, key))
sensors.append(ObihaiServiceSensors(pyobihai, serial, key))

for key in call_direction:
sensors.append(ObihaiServiceSensors(pyobihai, host, username, password, key))
sensors.append(ObihaiServiceSensors(pyobihai, serial, key))

add_entities(sensors)


class ObihaiServiceSensors(Entity):
"""Get the status of each Obihai Lines."""

def __init__(self, pyobihai, host, username, password, service_name):
def __init__(self, pyobihai, serial, service_name):
"""Initialize monitor sensor."""
self._host = host
self._username = username
self._password = password
self._service_name = service_name
self._state = None
self._name = f"{OBIHAI} {self._service_name}"
self._pyobihai = pyobihai
self._unique_id = f"{serial}-{self._service_name}"

@property
def name(self):
Expand All @@ -92,6 +92,18 @@ def state(self):
"""Return the state of the sensor."""
return self._state

@property
def available(self):
"""Return if sensor is available."""
if self._state is not None:
return True
return False

@property
def unique_id(self):
"""Return the unique ID."""
return self._unique_id

@property
def device_class(self):
"""Return the device class for uptime sensor."""
Expand All @@ -101,21 +113,17 @@ def device_class(self):

def update(self):
"""Update the sensor."""
services = self._pyobihai.get_state(self._host, self._username, self._password)
services = self._pyobihai.get_state()

if self._service_name in services:
self._state = services.get(self._service_name)

services = self._pyobihai.get_line_state(
self._host, self._username, self._password
)
services = self._pyobihai.get_line_state()

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
)
call_direction = self._pyobihai.get_call_direction()

if self._service_name in call_direction:
self._state = call_direction.get(self._service_name)
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ pynx584==0.4
pynzbgetapi==0.2.0

# homeassistant.components.obihai
pyobihai==1.1.1
pyobihai==1.2.0

# homeassistant.components.ombi
pyombi==0.1.5
Expand Down