1 """Support for command line covers."""
3 from __future__
import annotations
6 from datetime
import datetime, timedelta
7 from typing
import TYPE_CHECKING, Any, cast
27 from .const
import CONF_COMMAND_TIMEOUT, LOGGER, TRIGGER_ENTITY_OPTIONS
28 from .utils
import async_call_shell_with_timeout, async_check_output_or_log
36 async_add_entities: AddEntitiesCallback,
37 discovery_info: DiscoveryInfoType |
None =
None,
39 """Set up cover controlled by shell commands."""
40 if not discovery_info:
44 discovery_info = cast(DiscoveryInfoType, discovery_info)
45 entities: dict[str, dict[str, Any]] = {
46 slugify(discovery_info[CONF_NAME]): discovery_info
49 for device_name, cover_config
in entities.items():
50 trigger_entity_config = {
51 CONF_NAME:
Template(cover_config.get(CONF_NAME, device_name), hass),
52 **{k: v
for k, v
in cover_config.items()
if k
in TRIGGER_ENTITY_OPTIONS},
57 trigger_entity_config,
58 cover_config[CONF_COMMAND_OPEN],
59 cover_config[CONF_COMMAND_CLOSE],
60 cover_config[CONF_COMMAND_STOP],
61 cover_config.get(CONF_COMMAND_STATE),
62 cover_config.get(CONF_VALUE_TEMPLATE),
63 cover_config[CONF_COMMAND_TIMEOUT],
64 cover_config.get(CONF_SCAN_INTERVAL, SCAN_INTERVAL),
72 """Representation a command line cover."""
74 _attr_should_poll =
False
82 command_state: str |
None,
83 value_template: Template |
None,
85 scan_interval: timedelta,
87 """Initialize the cover."""
89 self.
_state_state: int |
None =
None
100 """Call when entity about to be added to hass."""
108 name=f
"Command Line Cover - {self.name}",
109 cancel_on_shutdown=
True,
114 """Execute the actual commands."""
115 LOGGER.debug(
"Running command: %s", command)
118 success = returncode == 0
122 "Command failed (with return code %s): %s", returncode, command
129 """Return if the cover is closed."""
136 """Return current position of cover.
138 None is unknown, 0 is closed, 100 is fully open.
143 """Query for the state."""
146 LOGGER.debug(
"Running state value command: %s", self.
_command_state_command_state)
150 """Update the state of the entity."""
155 "Updating Command Line Cover %s took longer than the scheduled update interval %s",
165 """Update device state."""
169 payload = self.
_value_template_value_template.async_render_with_possible_json_value(
179 """Update the entity.
181 Only used by the generic entity update service.
186 """Open the cover."""
191 """Close the cover."""
196 """Stop the cover."""
bool|None is_closed(self)
None async_open_cover(self, **Any kwargs)
bool _async_move_cover(self, str command)
int|None current_cover_position(self)
None __init__(self, ConfigType config, str command_open, str command_close, str command_stop, str|None command_state, Template|None value_template, int timeout, timedelta scan_interval)
None async_added_to_hass(self)
str|None _async_query_state(self)
None async_stop_cover(self, **Any kwargs)
None _update_entity_state(self, datetime|None now=None)
None async_close_cover(self, **Any kwargs)
int|None current_cover_position(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
str|UndefinedType|None name(self)
None _process_manual_data(self, Any|None value=None)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
int async_call_shell_with_timeout(str command, int timeout, *bool log_return_code=True)
str|None async_check_output_or_log(str command, int timeout)
CALLBACK_TYPE async_track_time_interval(HomeAssistant hass, Callable[[datetime], Coroutine[Any, Any, None]|None] action, timedelta interval, *str|None name=None, bool|None cancel_on_shutdown=None)