mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add Obihai integration (#26537)
* Add Obihai integration * Lint * Lint and bump library for multiple ports fix * Review comments * Review comments * Correct errors * Review comments * Review comments
This commit is contained in:
parent
1a73e6b44e
commit
2b30f47f4b
@ -435,6 +435,7 @@ omit =
|
|||||||
homeassistant/components/nut/sensor.py
|
homeassistant/components/nut/sensor.py
|
||||||
homeassistant/components/nx584/alarm_control_panel.py
|
homeassistant/components/nx584/alarm_control_panel.py
|
||||||
homeassistant/components/nzbget/sensor.py
|
homeassistant/components/nzbget/sensor.py
|
||||||
|
homeassistant/components/obihai/*
|
||||||
homeassistant/components/octoprint/*
|
homeassistant/components/octoprint/*
|
||||||
homeassistant/components/oem/climate.py
|
homeassistant/components/oem/climate.py
|
||||||
homeassistant/components/oasa_telematics/sensor.py
|
homeassistant/components/oasa_telematics/sensor.py
|
||||||
|
@ -197,6 +197,7 @@ homeassistant/components/nsw_fuel_station/* @nickw444
|
|||||||
homeassistant/components/nsw_rural_fire_service_feed/* @exxamalte
|
homeassistant/components/nsw_rural_fire_service_feed/* @exxamalte
|
||||||
homeassistant/components/nuki/* @pschmitt
|
homeassistant/components/nuki/* @pschmitt
|
||||||
homeassistant/components/nws/* @MatthewFlamm
|
homeassistant/components/nws/* @MatthewFlamm
|
||||||
|
homeassistant/components/obihai/* @dshokouhi
|
||||||
homeassistant/components/ohmconnect/* @robbiet480
|
homeassistant/components/ohmconnect/* @robbiet480
|
||||||
homeassistant/components/onboarding/* @home-assistant/core
|
homeassistant/components/onboarding/* @home-assistant/core
|
||||||
homeassistant/components/opentherm_gw/* @mvn23
|
homeassistant/components/opentherm_gw/* @mvn23
|
||||||
|
1
homeassistant/components/obihai/__init__.py
Normal file
1
homeassistant/components/obihai/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"""The Obihai integration."""
|
11
homeassistant/components/obihai/manifest.json
Normal file
11
homeassistant/components/obihai/manifest.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"domain": "obihai",
|
||||||
|
"name": "Obihai",
|
||||||
|
"documentation": "https://www.home-assistant.io/components/obihai",
|
||||||
|
"requirements": [
|
||||||
|
"pyobihai==1.0.2"
|
||||||
|
],
|
||||||
|
"dependencies": [],
|
||||||
|
"codeowners": ["@dshokouhi"]
|
||||||
|
}
|
||||||
|
|
104
homeassistant/components/obihai/sensor.py
Normal file
104
homeassistant/components/obihai/sensor.py
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
"""Support for Obihai Sensors."""
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from pyobihai import PyObihai
|
||||||
|
|
||||||
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
|
from homeassistant.const import (
|
||||||
|
CONF_HOST,
|
||||||
|
CONF_PASSWORD,
|
||||||
|
CONF_USERNAME,
|
||||||
|
DEVICE_CLASS_TIMESTAMP,
|
||||||
|
)
|
||||||
|
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
SCAN_INTERVAL = timedelta(seconds=5)
|
||||||
|
|
||||||
|
OBIHAI = "Obihai"
|
||||||
|
DEFAULT_USERNAME = "admin"
|
||||||
|
DEFAULT_PASSWORD = "admin"
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
|
{
|
||||||
|
vol.Required(CONF_HOST): cv.string,
|
||||||
|
vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
|
||||||
|
vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
|
"""Set up the Obihai sensor platform."""
|
||||||
|
|
||||||
|
username = config[CONF_USERNAME]
|
||||||
|
password = config[CONF_PASSWORD]
|
||||||
|
host = config[CONF_HOST]
|
||||||
|
|
||||||
|
sensors = []
|
||||||
|
|
||||||
|
pyobihai = PyObihai()
|
||||||
|
|
||||||
|
services = pyobihai.get_state(host, username, password)
|
||||||
|
|
||||||
|
line_services = pyobihai.get_line_state(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))
|
||||||
|
|
||||||
|
add_entities(sensors)
|
||||||
|
|
||||||
|
|
||||||
|
class ObihaiServiceSensors(Entity):
|
||||||
|
"""Get the status of each Obihai Lines."""
|
||||||
|
|
||||||
|
def __init__(self, pyobihai, host, username, password, 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
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return the name of the sensor."""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self):
|
||||||
|
"""Return the state of the sensor."""
|
||||||
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the device class for uptime sensor."""
|
||||||
|
if self._service_name == "Last Reboot":
|
||||||
|
return DEVICE_CLASS_TIMESTAMP
|
||||||
|
return None
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Update the sensor."""
|
||||||
|
services = self._pyobihai.get_state(self._host, self._username, self._password)
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
if self._service_name in services:
|
||||||
|
self._state = services.get(self._service_name)
|
@ -1344,6 +1344,9 @@ pynws==0.7.4
|
|||||||
# homeassistant.components.nx584
|
# homeassistant.components.nx584
|
||||||
pynx584==0.4
|
pynx584==0.4
|
||||||
|
|
||||||
|
# homeassistant.components.obihai
|
||||||
|
pyobihai==1.0.2
|
||||||
|
|
||||||
# homeassistant.components.openuv
|
# homeassistant.components.openuv
|
||||||
pyopenuv==1.0.9
|
pyopenuv==1.0.9
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user