@@ -231,10 +231,6 @@ def __init__(self, config: dict[str, Any]) -> None: # pylint: disable=super-ini
231231
232232 tilt_optimistic = config .get (CONF_TILT_OPTIMISTIC )
233233 self ._tilt_optimistic = tilt_optimistic or not self ._tilt_template
234- self ._position : int | None = None
235- self ._is_opening = False
236- self ._is_closing = False
237- self ._tilt_value : int | None = None
238234
239235 # The config requires (open and close scripts) or a set position script,
240236 # therefore the base supported features will always include them.
@@ -258,95 +254,67 @@ def _iterate_scripts(
258254 @property
259255 def is_closed (self ) -> bool | None :
260256 """Return if the cover is closed."""
261- if self ._position is None :
257+ if self ._attr_current_cover_position is None :
262258 return None
263259
264- return self ._position == 0
265-
266- @property
267- def is_opening (self ) -> bool :
268- """Return if the cover is currently opening."""
269- return self ._is_opening
270-
271- @property
272- def is_closing (self ) -> bool :
273- """Return if the cover is currently closing."""
274- return self ._is_closing
275-
276- @property
277- def current_cover_position (self ) -> int | None :
278- """Return current position of cover.
279-
280- None is unknown, 0 is closed, 100 is fully open.
281- """
282- if self ._position_template or POSITION_ACTION in self ._action_scripts :
283- return self ._position
284- return None
285-
286- @property
287- def current_cover_tilt_position (self ) -> int | None :
288- """Return current position of cover tilt.
289-
290- None is unknown, 0 is closed, 100 is fully open.
291- """
292- return self ._tilt_value
260+ return self ._attr_current_cover_position == 0
293261
294262 @callback
295263 def _update_position (self , result ):
296264 if result is None :
297- self ._position = None
265+ self ._attr_current_cover_position = None
298266 return
299267
300268 try :
301269 state = float (result )
302270 except ValueError as err :
303271 _LOGGER .error (err )
304- self ._position = None
272+ self ._attr_current_cover_position = None
305273 return
306274
307275 if state < 0 or state > 100 :
308- self ._position = None
276+ self ._attr_current_cover_position = None
309277 _LOGGER .error (
310278 "Cover position value must be between 0 and 100. Value was: %.2f" ,
311279 state ,
312280 )
313281 else :
314- self ._position = state
282+ self ._attr_current_cover_position = state
315283
316284 @callback
317285 def _update_tilt (self , result ):
318286 if result is None :
319- self ._tilt_value = None
287+ self ._attr_current_cover_tilt_position = None
320288 return
321289
322290 try :
323291 state = float (result )
324292 except ValueError as err :
325293 _LOGGER .error (err )
326- self ._tilt_value = None
294+ self ._attr_current_cover_tilt_position = None
327295 return
328296
329297 if state < 0 or state > 100 :
330- self ._tilt_value = None
298+ self ._attr_current_cover_tilt_position = None
331299 _LOGGER .error (
332300 "Tilt value must be between 0 and 100. Value was: %.2f" ,
333301 state ,
334302 )
335303 else :
336- self ._tilt_value = state
304+ self ._attr_current_cover_tilt_position = state
337305
338306 def _update_opening_and_closing (self , result : Any ) -> None :
339307 state = str (result ).lower ()
340308
341309 if state in _VALID_STATES :
342310 if not self ._position_template :
343311 if state in ("true" , OPEN_STATE ):
344- self ._position = 100
312+ self ._attr_current_cover_position = 100
345313 else :
346- self ._position = 0
314+ self ._attr_current_cover_position = 0
347315
348- self ._is_opening = state == OPENING_STATE
349- self ._is_closing = state == CLOSING_STATE
316+ self ._attr_is_opening = state == OPENING_STATE
317+ self ._attr_is_closing = state == CLOSING_STATE
350318 else :
351319 _LOGGER .error (
352320 "Received invalid cover is_on state: %s for entity %s. Expected: %s" ,
@@ -355,10 +323,10 @@ def _update_opening_and_closing(self, result: Any) -> None:
355323 ", " .join (_VALID_STATES ),
356324 )
357325 if not self ._position_template :
358- self ._position = None
326+ self ._attr_current_cover_position = None
359327
360- self ._is_opening = False
361- self ._is_closing = False
328+ self ._attr_is_opening = False
329+ self ._attr_is_closing = False
362330
363331 async def async_open_cover (self , ** kwargs : Any ) -> None :
364332 """Move the cover up."""
@@ -371,7 +339,7 @@ async def async_open_cover(self, **kwargs: Any) -> None:
371339 context = self ._context ,
372340 )
373341 if self ._attr_assumed_state :
374- self ._position = 100
342+ self ._attr_current_cover_position = 100
375343 self .async_write_ha_state ()
376344
377345 async def async_close_cover (self , ** kwargs : Any ) -> None :
@@ -385,7 +353,7 @@ async def async_close_cover(self, **kwargs: Any) -> None:
385353 context = self ._context ,
386354 )
387355 if self ._attr_assumed_state :
388- self ._position = 0
356+ self ._attr_current_cover_position = 0
389357 self .async_write_ha_state ()
390358
391359 async def async_stop_cover (self , ** kwargs : Any ) -> None :
@@ -395,43 +363,43 @@ async def async_stop_cover(self, **kwargs: Any) -> None:
395363
396364 async def async_set_cover_position (self , ** kwargs : Any ) -> None :
397365 """Set cover position."""
398- self ._position = kwargs [ATTR_POSITION ]
366+ self ._attr_current_cover_position = kwargs [ATTR_POSITION ]
399367 await self .async_run_script (
400368 self ._action_scripts [POSITION_ACTION ],
401- run_variables = {"position" : self ._position },
369+ run_variables = {"position" : self ._attr_current_cover_position },
402370 context = self ._context ,
403371 )
404372 if self ._attr_assumed_state :
405373 self .async_write_ha_state ()
406374
407375 async def async_open_cover_tilt (self , ** kwargs : Any ) -> None :
408376 """Tilt the cover open."""
409- self ._tilt_value = 100
377+ self ._attr_current_cover_tilt_position = 100
410378 await self .async_run_script (
411379 self ._action_scripts [TILT_ACTION ],
412- run_variables = {"tilt" : self ._tilt_value },
380+ run_variables = {"tilt" : self ._attr_current_cover_tilt_position },
413381 context = self ._context ,
414382 )
415383 if self ._tilt_optimistic :
416384 self .async_write_ha_state ()
417385
418386 async def async_close_cover_tilt (self , ** kwargs : Any ) -> None :
419387 """Tilt the cover closed."""
420- self ._tilt_value = 0
388+ self ._attr_current_cover_tilt_position = 0
421389 await self .async_run_script (
422390 self ._action_scripts [TILT_ACTION ],
423- run_variables = {"tilt" : self ._tilt_value },
391+ run_variables = {"tilt" : self ._attr_current_cover_tilt_position },
424392 context = self ._context ,
425393 )
426394 if self ._tilt_optimistic :
427395 self .async_write_ha_state ()
428396
429397 async def async_set_cover_tilt_position (self , ** kwargs : Any ) -> None :
430398 """Move the cover tilt to a specific position."""
431- self ._tilt_value = kwargs [ATTR_TILT_POSITION ]
399+ self ._attr_current_cover_tilt_position = kwargs [ATTR_TILT_POSITION ]
432400 await self .async_run_script (
433401 self ._action_scripts [TILT_ACTION ],
434- run_variables = {"tilt" : self ._tilt_value },
402+ run_variables = {"tilt" : self ._attr_current_cover_tilt_position },
435403 context = self ._context ,
436404 )
437405 if self ._tilt_optimistic :
@@ -467,19 +435,19 @@ def _async_setup_templates(self) -> None:
467435 """Set up templates."""
468436 if self ._template :
469437 self .add_template_attribute (
470- "_position " , self ._template , None , self ._update_state
438+ "_attr_current_cover_position " , self ._template , None , self ._update_state
471439 )
472440 if self ._position_template :
473441 self .add_template_attribute (
474- "_position " ,
442+ "_attr_current_cover_position " ,
475443 self ._position_template ,
476444 None ,
477445 self ._update_position ,
478446 none_on_template_error = True ,
479447 )
480448 if self ._tilt_template :
481449 self .add_template_attribute (
482- "_tilt_value " ,
450+ "_attr_current_cover_tilt_position " ,
483451 self ._tilt_template ,
484452 None ,
485453 self ._update_tilt ,
@@ -491,7 +459,7 @@ def _async_setup_templates(self) -> None:
491459 def _update_state (self , result ):
492460 super ()._update_state (result )
493461 if isinstance (result , TemplateError ):
494- self ._position = None
462+ self ._attr_current_cover_position = None
495463 return
496464
497465 self ._update_opening_and_closing (result )
0 commit comments