mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Bump pyobihai, add unique ID and availability (#26922)
* Bump pyobihai, add unique ID and availability * Fix unique ID * Fetch serial correctly
This commit is contained in:
parent
770ad86f12
commit
62cea2b7ac
@ -3,7 +3,7 @@
|
|||||||
"name": "Obihai",
|
"name": "Obihai",
|
||||||
"documentation": "https://www.home-assistant.io/components/obihai",
|
"documentation": "https://www.home-assistant.io/components/obihai",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"pyobihai==1.1.1"
|
"pyobihai==1.2.0"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@dshokouhi"]
|
"codeowners": ["@dshokouhi"]
|
||||||
|
@ -44,27 +44,29 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
|
|
||||||
pyobihai = PyObihai()
|
pyobihai = PyObihai(host, username, password)
|
||||||
|
|
||||||
login = pyobihai.check_account(host, username, password)
|
login = pyobihai.check_account()
|
||||||
if not login:
|
if not login:
|
||||||
_LOGGER.error("Invalid credentials")
|
_LOGGER.error("Invalid credentials")
|
||||||
return
|
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:
|
for key in services:
|
||||||
sensors.append(ObihaiServiceSensors(pyobihai, host, username, password, key))
|
sensors.append(ObihaiServiceSensors(pyobihai, serial, key))
|
||||||
|
|
||||||
for key in line_services:
|
for key in line_services:
|
||||||
sensors.append(ObihaiServiceSensors(pyobihai, host, username, password, key))
|
sensors.append(ObihaiServiceSensors(pyobihai, serial, key))
|
||||||
|
|
||||||
for key in call_direction:
|
for key in call_direction:
|
||||||
sensors.append(ObihaiServiceSensors(pyobihai, host, username, password, key))
|
sensors.append(ObihaiServiceSensors(pyobihai, serial, key))
|
||||||
|
|
||||||
add_entities(sensors)
|
add_entities(sensors)
|
||||||
|
|
||||||
@ -72,15 +74,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
class ObihaiServiceSensors(Entity):
|
class ObihaiServiceSensors(Entity):
|
||||||
"""Get the status of each Obihai Lines."""
|
"""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."""
|
"""Initialize monitor sensor."""
|
||||||
self._host = host
|
|
||||||
self._username = username
|
|
||||||
self._password = password
|
|
||||||
self._service_name = service_name
|
self._service_name = service_name
|
||||||
self._state = None
|
self._state = None
|
||||||
self._name = f"{OBIHAI} {self._service_name}"
|
self._name = f"{OBIHAI} {self._service_name}"
|
||||||
self._pyobihai = pyobihai
|
self._pyobihai = pyobihai
|
||||||
|
self._unique_id = f"{serial}-{self._service_name}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -92,6 +92,18 @@ class ObihaiServiceSensors(Entity):
|
|||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
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
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the device class for uptime sensor."""
|
"""Return the device class for uptime sensor."""
|
||||||
@ -101,21 +113,17 @@ class ObihaiServiceSensors(Entity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the sensor."""
|
"""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:
|
if self._service_name in services:
|
||||||
self._state = services.get(self._service_name)
|
self._state = services.get(self._service_name)
|
||||||
|
|
||||||
services = self._pyobihai.get_line_state(
|
services = self._pyobihai.get_line_state()
|
||||||
self._host, self._username, self._password
|
|
||||||
)
|
|
||||||
|
|
||||||
if self._service_name in services:
|
if self._service_name in services:
|
||||||
self._state = services.get(self._service_name)
|
self._state = services.get(self._service_name)
|
||||||
|
|
||||||
call_direction = self._pyobihai.get_call_direction(
|
call_direction = self._pyobihai.get_call_direction()
|
||||||
self._host, self._username, self._password
|
|
||||||
)
|
|
||||||
|
|
||||||
if self._service_name in call_direction:
|
if self._service_name in call_direction:
|
||||||
self._state = call_direction.get(self._service_name)
|
self._state = call_direction.get(self._service_name)
|
||||||
|
@ -1346,7 +1346,7 @@ pynx584==0.4
|
|||||||
pynzbgetapi==0.2.0
|
pynzbgetapi==0.2.0
|
||||||
|
|
||||||
# homeassistant.components.obihai
|
# homeassistant.components.obihai
|
||||||
pyobihai==1.1.1
|
pyobihai==1.2.0
|
||||||
|
|
||||||
# homeassistant.components.ombi
|
# homeassistant.components.ombi
|
||||||
pyombi==0.1.5
|
pyombi==0.1.5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user