Skip to content

Commit

Permalink
Merge pull request #18 from rasmusbe/better-name
Browse files Browse the repository at this point in the history
Nicer name for alarms
  • Loading branch information
AaronDavidSchneider authored Apr 13, 2021
2 parents 5811362 + 7246c9b commit 72cf0d2
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions custom_components/sonos_alarm/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ def __init__(self, soco, alarm):
self._is_available = True
speaker_info = self._soco.get_speaker_info(True)
self._unique_id = "{}-{}".format(soco.uid, self._id)
self._name = "Sonos {} Alarm (id: {})".format(
speaker_info["zone_name"], self._id
)
_entity_id = slugify("sonos_alarm_{}".format(self._id))
self.entity_id = ENTITY_ID_FORMAT.format(_entity_id)
self._model = speaker_info["model_name"]
Expand All @@ -131,6 +128,13 @@ def __init__(self, soco, alarm):
ATTR_PLAY_MODE: str(self.alarm.play_mode),
ATTR_SCHEDULED_TODAY: self._is_today
}

self._name = "Sonos Alarm {} {} {}".format(
speaker_info["zone_name"],
self.alarm.recurrence.title(),
str(self.alarm.start_time)[0:5]
)

_LOGGER.debug(self.alarm.recurrence)
super().__init__()
_LOGGER.debug("reached end of init")
Expand All @@ -151,6 +155,14 @@ def update(self, now=None):
ATTR_INCLUDE_LINKED_ZONES
] = self.alarm.include_linked_zones
self._is_available = True

speaker_info = self._soco.get_speaker_info(True)
self._name = "Sonos Alarm {} {} {}".format(
speaker_info["zone_name"],
self.alarm.recurrence.title(),
str(self.alarm.start_time)[0:5]
)

_LOGGER.debug("successfully updated alarms")
except SoCoException as exc:
_LOGGER.error(
Expand Down

0 comments on commit 72cf0d2

Please sign in to comment.