mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Replace local Barrier CC constants with library enums (#53109)
This commit is contained in:
parent
e6e1118dd4
commit
24cc5c8a0a
@ -5,6 +5,7 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
from zwave_js_server.client import Client as ZwaveClient
|
||||
from zwave_js_server.const import BarrierState
|
||||
from zwave_js_server.model.value import Value as ZwaveValue
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
@ -29,15 +30,6 @@ from .entity import ZWaveBaseEntity
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
BARRIER_TARGET_CLOSE = 0
|
||||
BARRIER_TARGET_OPEN = 255
|
||||
|
||||
BARRIER_STATE_CLOSED = 0
|
||||
BARRIER_STATE_CLOSING = 252
|
||||
BARRIER_STATE_STOPPED = 253
|
||||
BARRIER_STATE_OPENING = 254
|
||||
BARRIER_STATE_OPEN = 255
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
@ -172,14 +164,14 @@ class ZwaveMotorizedBarrier(ZWaveBaseEntity, CoverEntity):
|
||||
"""Return if the cover is opening or not."""
|
||||
if self.info.primary_value.value is None:
|
||||
return None
|
||||
return bool(self.info.primary_value.value == BARRIER_STATE_OPENING)
|
||||
return bool(self.info.primary_value.value == BarrierState.OPENING)
|
||||
|
||||
@property
|
||||
def is_closing(self) -> bool | None:
|
||||
"""Return if the cover is closing or not."""
|
||||
if self.info.primary_value.value is None:
|
||||
return None
|
||||
return bool(self.info.primary_value.value == BARRIER_STATE_CLOSING)
|
||||
return bool(self.info.primary_value.value == BarrierState.CLOSING)
|
||||
|
||||
@property
|
||||
def is_closed(self) -> bool | None:
|
||||
@ -190,15 +182,15 @@ class ZwaveMotorizedBarrier(ZWaveBaseEntity, CoverEntity):
|
||||
# issuing an open cover command. Return None in this case which
|
||||
# produces an unknown state and allows it to be resolved with an open
|
||||
# command.
|
||||
if self.info.primary_value.value == BARRIER_STATE_STOPPED:
|
||||
if self.info.primary_value.value == BarrierState.STOPPED:
|
||||
return None
|
||||
|
||||
return bool(self.info.primary_value.value == BARRIER_STATE_CLOSED)
|
||||
return bool(self.info.primary_value.value == BarrierState.CLOSED)
|
||||
|
||||
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||
"""Open the garage door."""
|
||||
await self.info.node.async_set_value(self._target_state, BARRIER_TARGET_OPEN)
|
||||
await self.info.node.async_set_value(self._target_state, BarrierState.OPEN)
|
||||
|
||||
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||
"""Close the garage door."""
|
||||
await self.info.node.async_set_value(self._target_state, BARRIER_TARGET_CLOSE)
|
||||
await self.info.node.async_set_value(self._target_state, BarrierState.CLOSED)
|
||||
|
@ -5,6 +5,7 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
from zwave_js_server.client import Client as ZwaveClient
|
||||
from zwave_js_server.const import BarrierEventSignalingSubsystemState
|
||||
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SwitchEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@ -19,10 +20,6 @@ from .entity import ZWaveBaseEntity
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
BARRIER_EVENT_SIGNALING_OFF = 0
|
||||
BARRIER_EVENT_SIGNALING_ON = 255
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
@ -108,7 +105,7 @@ class ZWaveBarrierEventSignalingSwitch(ZWaveBaseEntity, SwitchEntity):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the switch on."""
|
||||
await self.info.node.async_set_value(
|
||||
self.info.primary_value, BARRIER_EVENT_SIGNALING_ON
|
||||
self.info.primary_value, BarrierEventSignalingSubsystemState.ON
|
||||
)
|
||||
# this value is not refreshed, so assume success
|
||||
self._state = True
|
||||
@ -117,7 +114,7 @@ class ZWaveBarrierEventSignalingSwitch(ZWaveBaseEntity, SwitchEntity):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the switch off."""
|
||||
await self.info.node.async_set_value(
|
||||
self.info.primary_value, BARRIER_EVENT_SIGNALING_OFF
|
||||
self.info.primary_value, BarrierEventSignalingSubsystemState.OFF
|
||||
)
|
||||
# this value is not refreshed, so assume success
|
||||
self._state = False
|
||||
@ -127,4 +124,6 @@ class ZWaveBarrierEventSignalingSwitch(ZWaveBaseEntity, SwitchEntity):
|
||||
def _update_state(self) -> None:
|
||||
self._state = None
|
||||
if self.info.primary_value.value is not None:
|
||||
self._state = self.info.primary_value.value == BARRIER_EVENT_SIGNALING_ON
|
||||
self._state = (
|
||||
self.info.primary_value.value == BarrierEventSignalingSubsystemState.ON
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user