Skip to content

Commit 81fd9e1

Browse files
authored
Move state conversion from library to nasweb integration code (home-assistant#153208)
1 parent d108d5f commit 81fd9e1

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

homeassistant/components/nasweb/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"documentation": "https://www.home-assistant.io/integrations/nasweb",
88
"integration_type": "hub",
99
"iot_class": "local_push",
10-
"requirements": ["webio-api==0.1.11"]
10+
"requirements": ["webio-api==0.1.12"]
1111
}

homeassistant/components/nasweb/sensor.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
import time
77

88
from webio_api import Input as NASwebInput, TempSensor
9+
from webio_api.const import (
10+
STATE_INPUT_ACTIVE,
11+
STATE_INPUT_NORMAL,
12+
STATE_INPUT_PROBLEM,
13+
STATE_INPUT_TAMPER,
14+
STATE_INPUT_UNDEFINED,
15+
)
916

1017
from homeassistant.components.sensor import (
1118
DOMAIN as DOMAIN_SENSOR,
@@ -28,11 +35,6 @@
2835
from .const import DOMAIN, KEY_TEMP_SENSOR, STATUS_UPDATE_MAX_TIME_INTERVAL
2936

3037
SENSOR_INPUT_TRANSLATION_KEY = "sensor_input"
31-
STATE_UNDEFINED = "undefined"
32-
STATE_TAMPER = "tamper"
33-
STATE_ACTIVE = "active"
34-
STATE_NORMAL = "normal"
35-
STATE_PROBLEM = "problem"
3638

3739
_LOGGER = logging.getLogger(__name__)
3840

@@ -122,11 +124,11 @@ class InputStateSensor(BaseSensorEntity):
122124

123125
_attr_device_class = SensorDeviceClass.ENUM
124126
_attr_options: list[str] = [
125-
STATE_UNDEFINED,
126-
STATE_TAMPER,
127-
STATE_ACTIVE,
128-
STATE_NORMAL,
129-
STATE_PROBLEM,
127+
STATE_INPUT_ACTIVE,
128+
STATE_INPUT_NORMAL,
129+
STATE_INPUT_PROBLEM,
130+
STATE_INPUT_TAMPER,
131+
STATE_INPUT_UNDEFINED,
130132
]
131133
_attr_translation_key = SENSOR_INPUT_TRANSLATION_KEY
132134

homeassistant/components/nasweb/switch.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Any
88

99
from webio_api import Output as NASwebOutput
10+
from webio_api.const import STATE_ENTITY_UNAVAILABLE, STATE_OUTPUT_OFF, STATE_OUTPUT_ON
1011

1112
from homeassistant.components.switch import DOMAIN as DOMAIN_SWITCH, SwitchEntity
1213
from homeassistant.core import HomeAssistant, callback
@@ -25,6 +26,12 @@
2526

2627
OUTPUT_TRANSLATION_KEY = "switch_output"
2728

29+
NASWEB_STATE_TO_HA_STATE = {
30+
STATE_ENTITY_UNAVAILABLE: None,
31+
STATE_OUTPUT_ON: True,
32+
STATE_OUTPUT_OFF: False,
33+
}
34+
2835
_LOGGER = logging.getLogger(__name__)
2936

3037

@@ -105,7 +112,7 @@ async def async_added_to_hass(self) -> None:
105112
@callback
106113
def _handle_coordinator_update(self) -> None:
107114
"""Handle updated data from the coordinator."""
108-
self._attr_is_on = self._output.state
115+
self._attr_is_on = NASWEB_STATE_TO_HA_STATE[self._output.state]
109116
if (
110117
self.coordinator.last_update is None
111118
or time.time() - self._output.last_update >= STATUS_UPDATE_MAX_TIME_INTERVAL

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)