1 """Support for SwitchBot curtains."""
3 from __future__
import annotations
11 ATTR_CURRENT_POSITION,
12 ATTR_CURRENT_TILT_POSITION,
23 from .coordinator
import SwitchbotConfigEntry, SwitchbotDataUpdateCoordinator
24 from .entity
import SwitchbotEntity
27 _LOGGER = logging.getLogger(__name__)
33 entry: SwitchbotConfigEntry,
34 async_add_entities: AddEntitiesCallback,
36 """Set up Switchbot curtain based on a config entry."""
37 coordinator = entry.runtime_data
38 if isinstance(coordinator.device, switchbot.SwitchbotBlindTilt):
45 """Representation of a Switchbot."""
47 _device: switchbot.SwitchbotCurtain
48 _attr_device_class = CoverDeviceClass.CURTAIN
49 _attr_supported_features = (
50 CoverEntityFeature.OPEN
51 | CoverEntityFeature.CLOSE
52 | CoverEntityFeature.STOP
53 | CoverEntityFeature.SET_POSITION
55 _attr_translation_key =
"cover"
58 def __init__(self, coordinator: SwitchbotDataUpdateCoordinator) ->
None:
59 """Initialize the Switchbot."""
64 """Run when entity about to be added."""
67 if not last_state
or ATTR_CURRENT_POSITION
not in last_state.attributes:
78 """Open the curtain."""
80 _LOGGER.debug(
"Switchbot to open curtain %s", self.
_address_address)
87 """Close the curtain."""
89 _LOGGER.debug(
"Switchbot to close the curtain %s", self.
_address_address)
96 """Stop the moving of this device."""
98 _LOGGER.debug(
"Switchbot to stop %s", self.
_address_address)
105 """Move the cover shutter to a specific position."""
106 position = kwargs.get(ATTR_POSITION)
108 _LOGGER.debug(
"Switchbot to move at %d %s", position, self.
_address_address)
116 """Handle updated data from the coordinator."""
126 """Representation of a Switchbot."""
128 _device: switchbot.SwitchbotBlindTilt
129 _attr_device_class = CoverDeviceClass.BLIND
130 _attr_supported_features = (
131 CoverEntityFeature.OPEN_TILT
132 | CoverEntityFeature.CLOSE_TILT
133 | CoverEntityFeature.STOP_TILT
134 | CoverEntityFeature.SET_TILT_POSITION
137 _attr_translation_key =
"cover"
138 CLOSED_UP_THRESHOLD = 80
139 CLOSED_DOWN_THRESHOLD = 20
141 def __init__(self, coordinator: SwitchbotDataUpdateCoordinator) ->
None:
142 """Initialize the Switchbot."""
147 """Run when entity about to be added."""
150 if not last_state
or ATTR_CURRENT_TILT_POSITION
not in last_state.attributes:
154 ATTR_CURRENT_TILT_POSITION
157 if (_tilt := self._attr_current_cover_position)
is not None:
165 _LOGGER.debug(
"Switchbot to open blind tilt %s", self.
_address_address)
170 """Close the tilt."""
172 _LOGGER.debug(
"Switchbot to close the blind tilt %s", self.
_address_address)
177 """Stop the moving of this device."""
179 _LOGGER.debug(
"Switchbot to stop %s", self.
_address_address)
184 """Move the cover tilt to a specific position."""
185 position = kwargs.get(ATTR_TILT_POSITION)
187 _LOGGER.debug(
"Switchbot to move at %d %s", position, self.
_address_address)
193 """Handle updated data from the coordinator."""
bool|None is_opening(self)
bool|None is_closing(self)
None async_stop_cover_tilt(self, **Any kwargs)
None async_set_cover_tilt_position(self, **Any kwargs)
None async_added_to_hass(self)
int CLOSED_DOWN_THRESHOLD
None _handle_coordinator_update(self)
None async_open_cover_tilt(self, **Any kwargs)
None async_close_cover_tilt(self, **Any kwargs)
None __init__(self, SwitchbotDataUpdateCoordinator coordinator)
_attr_current_cover_tilt_position
None async_stop_cover(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
_attr_current_cover_position
None __init__(self, SwitchbotDataUpdateCoordinator coordinator)
None async_added_to_hass(self)
None async_open_cover(self, **Any kwargs)
None _handle_coordinator_update(self)
None async_set_cover_position(self, **Any kwargs)
dict[str, Any] parsed_data(self)
None async_write_ha_state(self)
State|None async_get_last_state(self)
None open(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, SwitchbotConfigEntry entry, AddEntitiesCallback async_add_entities)