1 """Support for MotionMount numeric control."""
3 from datetime
import timedelta
15 from .const
import DOMAIN, WALL_PRESET_NAME
16 from .entity
import MotionMountEntity
18 _LOGGER = logging.getLogger(__name__)
23 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
25 """Set up Vogel's MotionMount from a config entry."""
26 mm = hass.data[DOMAIN][entry.entry_id]
32 """The presets of a MotionMount."""
34 _attr_should_poll =
True
35 _attr_translation_key =
"motionmount_preset"
39 mm: motionmount.MotionMount,
40 config_entry: ConfigEntry,
42 """Initialize Preset selector."""
45 self.
_presets_presets: list[motionmount.Preset] = []
48 """Convert presets to select options."""
49 options = [f
"{preset.index}: {preset.name}" for preset
in presets]
50 options.insert(0, WALL_PRESET_NAME)
55 """Get latest state from MotionMount."""
61 except (TimeoutError, socket.gaierror)
as ex:
62 _LOGGER.warning(
"Failed to communicate with MotionMount: %s", ex)
68 """Get the current option."""
70 if self.
mmmm.is_moving:
75 if self.
mmmm.extension == 0
and self.
mmmm.turn == 0:
80 preset.extension == self.
mmmm.extension
81 and preset.turn == self.
mmmm.turn
89 """Set the new option."""
90 index =
int(option[:1])
92 await self.
mmmm.go_to_preset(index)
93 except (TimeoutError, socket.gaierror)
as ex:
95 translation_domain=DOMAIN,
96 translation_key=
"failed_communication",
bool _ensure_connected(self)
None async_select_option(self, str option)
str|None current_option(self)
None _update_options(self, list[motionmount.Preset] presets)
None __init__(self, motionmount.MotionMount mm, ConfigEntry config_entry)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)