mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Add Obihai reboot button (#88849)
* Obihai: Add reboot service * Switch to button * Remove button.py from coverage * Update homeassistant/components/obihai/const.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/obihai/button.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Update homeassistant/components/obihai/button.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * PR Feedback * Cleanup some typehints * As a class attr --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
a689ce7283
commit
1cb1dfa456
@ -809,6 +809,7 @@ omit =
|
|||||||
homeassistant/components/nx584/alarm_control_panel.py
|
homeassistant/components/nx584/alarm_control_panel.py
|
||||||
homeassistant/components/oasa_telematics/sensor.py
|
homeassistant/components/oasa_telematics/sensor.py
|
||||||
homeassistant/components/obihai/__init__.py
|
homeassistant/components/obihai/__init__.py
|
||||||
|
homeassistant/components/obihai/button.py
|
||||||
homeassistant/components/obihai/connectivity.py
|
homeassistant/components/obihai/connectivity.py
|
||||||
homeassistant/components/obihai/sensor.py
|
homeassistant/components/obihai/sensor.py
|
||||||
homeassistant/components/octoprint/__init__.py
|
homeassistant/components/octoprint/__init__.py
|
||||||
|
59
homeassistant/components/obihai/button.py
Normal file
59
homeassistant/components/obihai/button.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
"""Obihai button module."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pyobihai import PyObihai
|
||||||
|
|
||||||
|
from homeassistant.components.button import (
|
||||||
|
ButtonDeviceClass,
|
||||||
|
ButtonEntity,
|
||||||
|
ButtonEntityDescription,
|
||||||
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, EntityCategory
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
|
from homeassistant.helpers import entity_platform
|
||||||
|
|
||||||
|
from .connectivity import ObihaiConnection
|
||||||
|
from .const import OBIHAI
|
||||||
|
|
||||||
|
BUTTON_DESCRIPTION = ButtonEntityDescription(
|
||||||
|
key="reboot",
|
||||||
|
name=f"{OBIHAI} Reboot",
|
||||||
|
device_class=ButtonDeviceClass.RESTART,
|
||||||
|
entity_category=EntityCategory.CONFIG,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: ConfigEntry,
|
||||||
|
async_add_entities: entity_platform.AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up the Obihai sensor entries."""
|
||||||
|
username = entry.data[CONF_USERNAME]
|
||||||
|
password = entry.data[CONF_PASSWORD]
|
||||||
|
host = entry.data[CONF_HOST]
|
||||||
|
requester = ObihaiConnection(host, username, password)
|
||||||
|
|
||||||
|
await hass.async_add_executor_job(requester.update)
|
||||||
|
buttons = [ObihaiButton(requester.pyobihai, requester.serial)]
|
||||||
|
async_add_entities(buttons, update_before_add=True)
|
||||||
|
|
||||||
|
|
||||||
|
class ObihaiButton(ButtonEntity):
|
||||||
|
"""Obihai Reboot button."""
|
||||||
|
|
||||||
|
entity_description = BUTTON_DESCRIPTION
|
||||||
|
|
||||||
|
def __init__(self, pyobihai: PyObihai, serial: str) -> None:
|
||||||
|
"""Initialize monitor sensor."""
|
||||||
|
self._pyobihai = pyobihai
|
||||||
|
self._attr_unique_id = f"{serial}-reboot"
|
||||||
|
|
||||||
|
def press(self) -> None:
|
||||||
|
"""Press button."""
|
||||||
|
|
||||||
|
if not self._pyobihai.call_reboot():
|
||||||
|
raise HomeAssistantError("Reboot failed!")
|
@ -45,7 +45,7 @@ class ObihaiConnection:
|
|||||||
self.host = host
|
self.host = host
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
self.serial: list = []
|
self.serial: str
|
||||||
self.services: list = []
|
self.services: list = []
|
||||||
self.line_services: list = []
|
self.line_services: list = []
|
||||||
self.call_direction: list = []
|
self.call_direction: list = []
|
||||||
|
@ -12,4 +12,4 @@ OBIHAI = "Obihai"
|
|||||||
|
|
||||||
LOGGER = logging.getLogger(__package__)
|
LOGGER = logging.getLogger(__package__)
|
||||||
|
|
||||||
PLATFORMS: Final = [Platform.SENSOR]
|
PLATFORMS: Final = [Platform.BUTTON, Platform.SENSOR]
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from pyobihai import PyObihai
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
@ -89,7 +90,7 @@ async def async_setup_entry(
|
|||||||
class ObihaiServiceSensors(SensorEntity):
|
class ObihaiServiceSensors(SensorEntity):
|
||||||
"""Get the status of each Obihai Lines."""
|
"""Get the status of each Obihai Lines."""
|
||||||
|
|
||||||
def __init__(self, pyobihai, serial, service_name):
|
def __init__(self, pyobihai: PyObihai, serial: str, service_name: str) -> None:
|
||||||
"""Initialize monitor sensor."""
|
"""Initialize monitor sensor."""
|
||||||
self._service_name = service_name
|
self._service_name = service_name
|
||||||
self._state = None
|
self._state = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user