Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jtbgroup committed Apr 30, 2023
2 parents 83178e5 + 6a3104b commit a43c9da
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# KODI MEDIA SENSOR - Changelog

## 5.1.2

- Bugfix : Recently added movie wasn't publishing anything due to a state issue. (see [issue #28](https://github.com/jtbgroup/kodi-media-sensors/issues/28)). Thanks to [Rudd-O](https://github.com/Rudd-O).

## 5.1.1

- Bugfix: auto clean functionality didn't works as it should due to a wrong time conversion
Expand Down
46 changes: 42 additions & 4 deletions custom_components/kodi_media_sensors/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Optional
from urllib import parse

import homeassistant
from homeassistant.const import STATE_OFF, STATE_ON, STATE_PROBLEM, STATE_UNKNOWN
from homeassistant.helpers.entity import Entity
from pykodi import Kodi
Expand All @@ -20,14 +21,32 @@ class KodiMediaEntity(Entity):
update_method: str = NotImplemented

def __init__(
self, unique_id, kodi: Kodi, config: KodiConfig, hide_watched: bool = False
self,
unique_id,
hass,
kodi: Kodi,
kodi_entity_id,
config: KodiConfig,
hide_watched: bool = False,
) -> None:
super().__init__()
self._unique_id = unique_id
self._hass = hass
self.kodi = kodi
self.hide_watched = hide_watched
self.data = []
self._state = None
self._state = STATE_OFF

homeassistant.helpers.event.async_track_state_change_event(
hass, kodi_entity_id, self.__handle_event
)

# TODO: populate immediately the data if kodi is running
kodi_state = self._hass.states.get(kodi_entity_id).state
if kodi_state is None or kodi_state == STATE_OFF:
self._state = STATE_OFF
else:
self._state = STATE_ON

protocol = "https" if config["ssl"] else "http"
auth = ""
Expand All @@ -50,6 +69,11 @@ def name(self):
def state(self) -> Optional[str]:
return self._state

async def __handle_event(self, event):
newstate = event.data.get("new_state").state
self._state = STATE_OFF if newstate == STATE_OFF else STATE_ON
self._hass.async_create_task(self.async_update_ha_state(True))

async def async_update(self) -> None:
result = None
try:
Expand Down Expand Up @@ -125,12 +149,19 @@ class KodiRecentlyAddedTVEntity(KodiMediaEntity):
def __init__(
self,
config_unique_id,
hass,
kodi: Kodi,
kodi_entity_id,
config: KodiConfig,
hide_watched: bool = False,
) -> None:
super().__init__(
_UNIQUE_ID_PREFIX_TV_ADDED + config_unique_id, kodi, config, hide_watched
_UNIQUE_ID_PREFIX_TV_ADDED + config_unique_id,
hass,
kodi,
kodi_entity_id,
config,
hide_watched,
)

@property
Expand Down Expand Up @@ -205,12 +236,19 @@ class KodiRecentlyAddedMoviesEntity(KodiMediaEntity):
def __init__(
self,
config_unique_id,
hass,
kodi: Kodi,
kodi_entity_id,
config: KodiConfig,
hide_watched: bool = False,
) -> None:
super().__init__(
_UNIQUE_ID_PREFIX_MOVIE_ADDED + config_unique_id, kodi, config, hide_watched
_UNIQUE_ID_PREFIX_MOVIE_ADDED + config_unique_id,
hass,
kodi,
kodi_entity_id,
config,
hide_watched,
)

# @property
Expand Down
2 changes: 1 addition & 1 deletion custom_components/kodi_media_sensors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"integration_type": "hub",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/jtbgroup/kodi-media-sensors/issues",
"version": "5.1.1"
"version": "5.1.2"
}
4 changes: 4 additions & 0 deletions custom_components/kodi_media_sensors/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ async def async_setup_entry(
if conf.get(CONF_SENSOR_RECENTLY_ADDED_TVSHOW):
tv_entity = KodiRecentlyAddedTVEntity(
config_entry.entry_id,
hass,
kodi,
kodi_entity_id,
kodi_config_entry.data,
hide_watched=conf.get(OPTION_HIDE_WATCHED, False),
)
Expand All @@ -115,7 +117,9 @@ async def async_setup_entry(
if conf.get(CONF_SENSOR_RECENTLY_ADDED_MOVIE):
movies_entity = KodiRecentlyAddedMoviesEntity(
config_entry.entry_id,
hass,
kodi,
kodi_entity_id,
kodi_config_entry.data,
hide_watched=conf.get(OPTION_HIDE_WATCHED, False),
)
Expand Down

0 comments on commit a43c9da

Please sign in to comment.