Migrate group to use shorthand attributes for name and icon (#115244)

This commit is contained in:
J. Nick Koston 2024-04-08 11:05:56 -10:00 committed by GitHub
parent 95958ac0ef
commit aa85e59c6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 20 deletions

View File

@ -277,11 +277,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
await group.async_update_tracked_entity_ids(entity_ids) await group.async_update_tracked_entity_ids(entity_ids)
if ATTR_NAME in service.data: if ATTR_NAME in service.data:
group.name = service.data[ATTR_NAME] group.set_name(service.data[ATTR_NAME])
need_update = True need_update = True
if ATTR_ICON in service.data: if ATTR_ICON in service.data:
group.icon = service.data[ATTR_ICON] group.set_icon(service.data[ATTR_ICON])
need_update = True need_update = True
if ATTR_ALL in service.data: if ATTR_ALL in service.data:

View File

@ -150,9 +150,9 @@ class Group(Entity):
This Object has factory function for creation. This Object has factory function for creation.
""" """
self.hass = hass self.hass = hass
self._name = name self._attr_name = name
self._state: str | None = None self._state: str | None = None
self._icon = icon self._attr_icon = icon
self._set_tracked(entity_ids) self._set_tracked(entity_ids)
self._on_off: dict[str, bool] = {} self._on_off: dict[str, bool] = {}
self._assumed: dict[str, bool] = {} self._assumed: dict[str, bool] = {}
@ -234,30 +234,18 @@ class Group(Entity):
await async_get_component(hass).async_add_entities([group]) await async_get_component(hass).async_add_entities([group])
return group return group
@property def set_name(self, value: str) -> None:
def name(self) -> str:
"""Return the name of the group."""
return self._name
@name.setter
def name(self, value: str) -> None:
"""Set Group name.""" """Set Group name."""
self._name = value self._attr_name = value
@property @property
def state(self) -> str | None: def state(self) -> str | None:
"""Return the state of the group.""" """Return the state of the group."""
return self._state return self._state
@property def set_icon(self, value: str | None) -> None:
def icon(self) -> str | None:
"""Return the icon of the group."""
return self._icon
@icon.setter
def icon(self, value: str | None) -> None:
"""Set Icon for group.""" """Set Icon for group."""
self._icon = value self._attr_icon = value
@property @property
def extra_state_attributes(self) -> dict[str, Any]: def extra_state_attributes(self) -> dict[str, Any]: