Skip to content

Commit

Permalink
uuid for old entities
Browse files Browse the repository at this point in the history
  • Loading branch information
jtbgroup committed Feb 27, 2023
1 parent 290e8e5 commit f5b8813
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
68 changes: 51 additions & 17 deletions custom_components/kodi_media_sensors/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from .types import ExtraStateAttrs, KodiConfig

_LOGGER = logging.getLogger(__name__)
_UNIQUE_ID_PREFIX_TV_ADDED = "kms_t_"
_UNIQUE_ID_PREFIX_MOVIE_ADDED = "kms_m_"


class KodiMediaEntity(Entity):
Expand All @@ -18,9 +20,10 @@ class KodiMediaEntity(Entity):
update_method: str = NotImplemented

def __init__(
self, kodi: Kodi, config: KodiConfig, hide_watched: bool = False
self, unique_id, kodi: Kodi, config: KodiConfig, hide_watched: bool = False
) -> None:
super().__init__()
self._unique_id = unique_id
self.kodi = kodi
self.hide_watched = hide_watched
self.data = []
Expand All @@ -34,6 +37,15 @@ def __init__(
f"{protocol}://{auth}{config['host']}:{config['port']}/image/image%3A%2F%2F"
)

@property
def unique_id(self):
"""Return the unique id of the device."""
return self._unique_id

@property
def name(self):
return self._unique_id

@property
def state(self) -> Optional[str]:
return self._state
Expand Down Expand Up @@ -110,17 +122,28 @@ class KodiRecentlyAddedTVEntity(KodiMediaEntity):
update_method = "VideoLibrary.GetRecentlyAddedEpisodes"
result_key = "episodes"

@property
def unique_id(self) -> str:
"""The unique ID of the entity.
It's important to define this, otherwise the entities created will not show up
on the configured integration card as associated with the integration.
"""
return self.name
def __init__(
self,
config_unique_id,
kodi: Kodi,
config: KodiConfig,
hide_watched: bool = False,
) -> None:
super().__init__(
_UNIQUE_ID_PREFIX_TV_ADDED + config_unique_id, kodi, config, hide_watched
)

@property
def name(self) -> str:
return "kodi_recently_added_tv"
# @property
# def unique_id(self) -> str:
# """The unique ID of the entity.
# It's important to define this, otherwise the entities created will not show up
# on the configured integration card as associated with the integration.
# """
# return self.name

# @property
# def name(self) -> str:
# return "kodi_recently_added_tv"

@property
def extra_state_attributes(self) -> ExtraStateAttrs:
Expand Down Expand Up @@ -191,13 +214,24 @@ class KodiRecentlyAddedMoviesEntity(KodiMediaEntity):
update_method = "VideoLibrary.GetRecentlyAddedMovies"
result_key = "movies"

@property
def unique_id(self) -> str:
return self.name
def __init__(
self,
config_unique_id,
kodi: Kodi,
config: KodiConfig,
hide_watched: bool = False,
) -> None:
super().__init__(
_UNIQUE_ID_PREFIX_MOVIE_ADDED + config_unique_id, kodi, config, hide_watched
)

@property
def name(self) -> str:
return "kodi_recently_added_movies"
# @property
# def unique_id(self) -> str:
# return self.name

# @property
# def name(self) -> str:
# return "kodi_recently_added_movies"

@property
def extra_state_attributes(self) -> ExtraStateAttrs:
Expand Down
2 changes: 2 additions & 0 deletions custom_components/kodi_media_sensors/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ async def async_setup_entry(

if conf.get(CONF_SENSOR_RECENTLY_ADDED_TVSHOW):
tv_entity = KodiRecentlyAddedTVEntity(
config_entry.entry_id,
kodi,
kodi_config_entry.data,
hide_watched=conf.get(OPTION_HIDE_WATCHED, False),
Expand All @@ -113,6 +114,7 @@ async def async_setup_entry(

if conf.get(CONF_SENSOR_RECENTLY_ADDED_MOVIE):
movies_entity = KodiRecentlyAddedMoviesEntity(
config_entry.entry_id,
kodi,
kodi_config_entry.data,
hide_watched=conf.get(OPTION_HIDE_WATCHED, False),
Expand Down

0 comments on commit f5b8813

Please sign in to comment.