1 """Support for LCN covers."""
3 from collections.abc
import Iterable
4 from functools
import partial
17 ADD_ENTITIES_CALLBACKS,
23 from .entity
import LcnEntity
24 from .helpers
import InputType
30 config_entry: ConfigEntry,
31 async_add_entities: AddEntitiesCallback,
32 entity_configs: Iterable[ConfigType],
34 """Add entities for this domain."""
35 entities: list[LcnOutputsCover | LcnRelayCover] = []
36 for entity_config
in entity_configs:
37 if entity_config[CONF_DOMAIN_DATA][CONF_MOTOR]
in "OUTPUTS":
47 config_entry: ConfigEntry,
48 async_add_entities: AddEntitiesCallback,
50 """Set up LCN cover entities from a config entry."""
51 add_entities = partial(
57 hass.data[DOMAIN][config_entry.entry_id][ADD_ENTITIES_CALLBACKS].
update(
58 {DOMAIN_COVER: add_entities}
64 for entity_config
in config_entry.data[CONF_ENTITIES]
65 if entity_config[CONF_DOMAIN] == DOMAIN_COVER
71 """Representation of a LCN cover connected to output ports."""
73 _attr_is_closed =
False
74 _attr_is_closing =
False
75 _attr_is_opening =
False
76 _attr_assumed_state =
True
78 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
79 """Initialize the LCN cover."""
80 super().
__init__(config, config_entry)
83 pypck.lcn_defs.OutputPort[
"OUTPUTUP"].value,
84 pypck.lcn_defs.OutputPort[
"OUTPUTDOWN"].value,
86 if CONF_REVERSE_TIME
in config[CONF_DOMAIN_DATA]:
88 config[CONF_DOMAIN_DATA][CONF_REVERSE_TIME]
94 """Run when entity about to be added to hass."""
98 pypck.lcn_defs.OutputPort[
"OUTPUTUP"]
101 pypck.lcn_defs.OutputPort[
"OUTPUTDOWN"]
105 """Run when entity will be removed from hass."""
109 pypck.lcn_defs.OutputPort[
"OUTPUTUP"]
112 pypck.lcn_defs.OutputPort[
"OUTPUTDOWN"]
116 """Close the cover."""
117 state = pypck.lcn_defs.MotorStateModifier.DOWN
127 """Open the cover."""
128 state = pypck.lcn_defs.MotorStateModifier.UP
139 """Stop the cover."""
140 state = pypck.lcn_defs.MotorStateModifier.STOP
141 if not await self.
device_connectiondevice_connection.control_motors_outputs(state):
148 """Set cover states when LCN input object (command) is received."""
150 not isinstance(input_obj, pypck.inputs.ModStatusOutput)
151 or input_obj.get_output_id()
not in self.
output_idsoutput_ids
155 if input_obj.get_percent() > 0:
156 if input_obj.get_output_id() == self.
output_idsoutput_ids[0]:
173 """Representation of a LCN cover connected to relays."""
175 _attr_is_closed =
False
176 _attr_is_closing =
False
177 _attr_is_opening =
False
178 _attr_assumed_state =
True
180 def __init__(self, config: ConfigType, config_entry: ConfigEntry) ->
None:
181 """Initialize the LCN cover."""
182 super().
__init__(config, config_entry)
184 self.
motormotor = pypck.lcn_defs.MotorPort[config[CONF_DOMAIN_DATA][CONF_MOTOR]]
193 """Run when entity about to be added to hass."""
199 """Run when entity will be removed from hass."""
205 """Close the cover."""
206 states = [pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4
207 states[self.
motormotor.value] = pypck.lcn_defs.MotorStateModifier.DOWN
208 if not await self.
device_connectiondevice_connection.control_motors_relays(states):
215 """Open the cover."""
216 states = [pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4
217 states[self.
motormotor.value] = pypck.lcn_defs.MotorStateModifier.UP
218 if not await self.
device_connectiondevice_connection.control_motors_relays(states):
226 """Stop the cover."""
227 states = [pypck.lcn_defs.MotorStateModifier.NOCHANGE] * 4
228 states[self.
motormotor.value] = pypck.lcn_defs.MotorStateModifier.STOP
229 if not await self.
device_connectiondevice_connection.control_motors_relays(states):
236 """Set cover states when LCN input object (command) is received."""
237 if not isinstance(input_obj, pypck.inputs.ModStatusRelays):
240 states = input_obj.states
None async_added_to_hass(self)
None async_open_cover(self, **Any kwargs)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None input_received(self, InputType input_obj)
None async_stop_cover(self, **Any kwargs)
None async_will_remove_from_hass(self)
None async_close_cover(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
None __init__(self, ConfigType config, ConfigEntry config_entry)
None async_added_to_hass(self)
None async_open_cover(self, **Any kwargs)
None async_will_remove_from_hass(self)
None input_received(self, InputType input_obj)
None async_stop_cover(self, **Any kwargs)
None async_write_ha_state(self)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
IssData update(pyiss.ISS iss)
None add_lcn_entities(ConfigEntry config_entry, AddEntitiesCallback async_add_entities, Iterable[ConfigType] entity_configs)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)