Move state conversion from library to nasweb integration code (#153208)

This commit is contained in:
nasWebio
2025-10-14 13:21:19 +02:00
committed by GitHub
parent d108d5f106
commit 81fd9e1c5a
5 changed files with 23 additions and 14 deletions

View File

@@ -7,5 +7,5 @@
"documentation": "https://www.home-assistant.io/integrations/nasweb",
"integration_type": "hub",
"iot_class": "local_push",
"requirements": ["webio-api==0.1.11"]
"requirements": ["webio-api==0.1.12"]
}

View File

@@ -6,6 +6,13 @@ import logging
import time
from webio_api import Input as NASwebInput, TempSensor
from webio_api.const import (
STATE_INPUT_ACTIVE,
STATE_INPUT_NORMAL,
STATE_INPUT_PROBLEM,
STATE_INPUT_TAMPER,
STATE_INPUT_UNDEFINED,
)
from homeassistant.components.sensor import (
DOMAIN as DOMAIN_SENSOR,
@@ -28,11 +35,6 @@ from . import NASwebConfigEntry
from .const import DOMAIN, KEY_TEMP_SENSOR, STATUS_UPDATE_MAX_TIME_INTERVAL
SENSOR_INPUT_TRANSLATION_KEY = "sensor_input"
STATE_UNDEFINED = "undefined"
STATE_TAMPER = "tamper"
STATE_ACTIVE = "active"
STATE_NORMAL = "normal"
STATE_PROBLEM = "problem"
_LOGGER = logging.getLogger(__name__)
@@ -122,11 +124,11 @@ class InputStateSensor(BaseSensorEntity):
_attr_device_class = SensorDeviceClass.ENUM
_attr_options: list[str] = [
STATE_UNDEFINED,
STATE_TAMPER,
STATE_ACTIVE,
STATE_NORMAL,
STATE_PROBLEM,
STATE_INPUT_ACTIVE,
STATE_INPUT_NORMAL,
STATE_INPUT_PROBLEM,
STATE_INPUT_TAMPER,
STATE_INPUT_UNDEFINED,
]
_attr_translation_key = SENSOR_INPUT_TRANSLATION_KEY

View File

@@ -7,6 +7,7 @@ import time
from typing import Any
from webio_api import Output as NASwebOutput
from webio_api.const import STATE_ENTITY_UNAVAILABLE, STATE_OUTPUT_OFF, STATE_OUTPUT_ON
from homeassistant.components.switch import DOMAIN as DOMAIN_SWITCH, SwitchEntity
from homeassistant.core import HomeAssistant, callback
@@ -25,6 +26,12 @@ from .coordinator import NASwebCoordinator
OUTPUT_TRANSLATION_KEY = "switch_output"
NASWEB_STATE_TO_HA_STATE = {
STATE_ENTITY_UNAVAILABLE: None,
STATE_OUTPUT_ON: True,
STATE_OUTPUT_OFF: False,
}
_LOGGER = logging.getLogger(__name__)
@@ -105,7 +112,7 @@ class RelaySwitch(SwitchEntity, BaseCoordinatorEntity):
@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._attr_is_on = self._output.state
self._attr_is_on = NASWEB_STATE_TO_HA_STATE[self._output.state]
if (
self.coordinator.last_update is None
or time.time() - self._output.last_update >= STATUS_UPDATE_MAX_TIME_INTERVAL

2
requirements_all.txt generated
View File

@@ -3147,7 +3147,7 @@ weatherflow4py==1.4.1
webexpythonsdk==2.0.1
# homeassistant.components.nasweb
webio-api==0.1.11
webio-api==0.1.12
# homeassistant.components.webmin
webmin-xmlrpc==0.0.2

View File

@@ -2606,7 +2606,7 @@ watergate-local-api==2024.4.1
weatherflow4py==1.4.1
# homeassistant.components.nasweb
webio-api==0.1.11
webio-api==0.1.12
# homeassistant.components.webmin
webmin-xmlrpc==0.0.2