mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Use entity class attributes for alert (#52518)
This commit is contained in:
parent
e2b89e4650
commit
e9453bb344
@ -152,6 +152,8 @@ async def async_setup(hass, config):
|
|||||||
class Alert(ToggleEntity):
|
class Alert(ToggleEntity):
|
||||||
"""Representation of an alert."""
|
"""Representation of an alert."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass,
|
hass,
|
||||||
@ -170,7 +172,7 @@ class Alert(ToggleEntity):
|
|||||||
):
|
):
|
||||||
"""Initialize the alert."""
|
"""Initialize the alert."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self._name = name
|
self._attr_name = name
|
||||||
self._alert_state = state
|
self._alert_state = state
|
||||||
self._skip_first = skip_first
|
self._skip_first = skip_first
|
||||||
self._data = data
|
self._data = data
|
||||||
@ -203,16 +205,6 @@ class Alert(ToggleEntity):
|
|||||||
hass, [watched_entity_id], self.watched_entity_change
|
hass, [watched_entity_id], self.watched_entity_change
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the alert."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def should_poll(self):
|
|
||||||
"""Home Assistant need not poll these entities."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the alert status."""
|
"""Return the alert status."""
|
||||||
@ -235,7 +227,7 @@ class Alert(ToggleEntity):
|
|||||||
|
|
||||||
async def begin_alerting(self):
|
async def begin_alerting(self):
|
||||||
"""Begin the alert procedures."""
|
"""Begin the alert procedures."""
|
||||||
_LOGGER.debug("Beginning Alert: %s", self._name)
|
_LOGGER.debug("Beginning Alert: %s", self._attr_name)
|
||||||
self._ack = False
|
self._ack = False
|
||||||
self._firing = True
|
self._firing = True
|
||||||
self._next_delay = 0
|
self._next_delay = 0
|
||||||
@ -249,7 +241,7 @@ class Alert(ToggleEntity):
|
|||||||
|
|
||||||
async def end_alerting(self):
|
async def end_alerting(self):
|
||||||
"""End the alert procedures."""
|
"""End the alert procedures."""
|
||||||
_LOGGER.debug("Ending Alert: %s", self._name)
|
_LOGGER.debug("Ending Alert: %s", self._attr_name)
|
||||||
self._cancel()
|
self._cancel()
|
||||||
self._ack = False
|
self._ack = False
|
||||||
self._firing = False
|
self._firing = False
|
||||||
@ -272,13 +264,13 @@ class Alert(ToggleEntity):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if not self._ack:
|
if not self._ack:
|
||||||
_LOGGER.info("Alerting: %s", self._name)
|
_LOGGER.info("Alerting: %s", self._attr_name)
|
||||||
self._send_done_message = True
|
self._send_done_message = True
|
||||||
|
|
||||||
if self._message_template is not None:
|
if self._message_template is not None:
|
||||||
message = self._message_template.async_render(parse_result=False)
|
message = self._message_template.async_render(parse_result=False)
|
||||||
else:
|
else:
|
||||||
message = self._name
|
message = self._attr_name
|
||||||
|
|
||||||
await self._send_notification_message(message)
|
await self._send_notification_message(message)
|
||||||
await self._schedule_notify()
|
await self._schedule_notify()
|
||||||
@ -314,13 +306,13 @@ class Alert(ToggleEntity):
|
|||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Async Unacknowledge alert."""
|
"""Async Unacknowledge alert."""
|
||||||
_LOGGER.debug("Reset Alert: %s", self._name)
|
_LOGGER.debug("Reset Alert: %s", self._attr_name)
|
||||||
self._ack = False
|
self._ack = False
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Async Acknowledge alert."""
|
"""Async Acknowledge alert."""
|
||||||
_LOGGER.debug("Acknowledged Alert: %s", self._name)
|
_LOGGER.debug("Acknowledged Alert: %s", self._attr_name)
|
||||||
self._ack = True
|
self._ack = True
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user