1 """Support for ISY covers."""
3 from __future__
import annotations
5 from typing
import Any, cast
7 from pyisy.constants
import ISY_VALUE_UNKNOWN
20 from .const
import _LOGGER, DOMAIN, UOM_8_BIT_RANGE
21 from .entity
import ISYNodeEntity, ISYProgramEntity
22 from .models
import IsyData
26 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
28 """Set up the ISY cover platform."""
29 isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
30 devices: dict[str, DeviceInfo] = isy_data.devices
31 entities: list[ISYCoverEntity | ISYCoverProgramEntity] = [
33 for node
in isy_data.nodes[Platform.COVER]
38 for name, status, actions
in isy_data.programs[Platform.COVER]
45 """Representation of an ISY cover device."""
47 _attr_supported_features = (
48 CoverEntityFeature.OPEN
49 | CoverEntityFeature.CLOSE
50 | CoverEntityFeature.SET_POSITION
55 """Return the current cover position."""
56 if self.
_node_node.status == ISY_VALUE_UNKNOWN:
58 if self.
_node_node.uom == UOM_8_BIT_RANGE:
59 return round(cast(float, self.
_node_node.status) * 100.0 / 255.0)
60 return int(sorted((0, self.
_node_node.status, 100))[1])
64 """Get whether the ISY cover device is closed."""
65 if self.
_node_node.status == ISY_VALUE_UNKNOWN:
70 """Send the open cover command to the ISY cover device."""
71 if not await self.
_node_node.turn_on():
72 _LOGGER.error(
"Unable to open the cover")
75 """Send the close cover command to the ISY cover device."""
76 if not await self.
_node_node.turn_off():
77 _LOGGER.error(
"Unable to close the cover")
80 """Move the cover to a specific position."""
81 position = kwargs[ATTR_POSITION]
82 if self.
_node_node.uom == UOM_8_BIT_RANGE:
83 position = round(position * 255.0 / 100.0)
84 if not await self.
_node_node.turn_on(val=position):
85 _LOGGER.error(
"Unable to set cover position")
89 """Representation of an ISY cover program."""
93 """Get whether the ISY cover program is closed."""
97 """Send the open cover command to the ISY cover program."""
98 if not await self.
_actions_actions.run_then():
99 _LOGGER.error(
"Unable to open the cover")
102 """Send the close cover command to the ISY cover program."""
103 if not await self.
_actions_actions.run_else():
104 _LOGGER.error(
"Unable to close the cover")
None async_open_cover(self, **Any kwargs)
bool|None is_closed(self)
None async_close_cover(self, **Any kwargs)
None async_set_cover_position(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)