-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Add Obihai integration #26537
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
Add Obihai integration #26537
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d5e3fa4
Add Obihai integration
dshokouhi 0e34453
Lint
dshokouhi 81ce679
Lint and bump library for multiple ports fix
dshokouhi b087e83
Review comments
dshokouhi 07ae7aa
Review comments
dshokouhi 8dab431
Correct errors
dshokouhi b97533b
Review comments
dshokouhi 3245cf3
Review comments
dshokouhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """The Obihai integration.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "domain": "obihai", | ||
| "name": "Obihai", | ||
| "documentation": "https://www.home-assistant.io/components/obihai", | ||
| "requirements": [ | ||
| "pyobihai==1.0.2" | ||
| ], | ||
| "dependencies": [], | ||
| "codeowners": ["@dshokouhi"] | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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: | ||
|
MartinHjelmare marked this conversation as resolved.
|
||
| self._state = services.get(self._service_name) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.