Skip to content

Commit b0b6ab2

Browse files
authored
Set mediatype (#74)
1 parent 9ed203a commit b0b6ab2

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

lghorizon/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
LGHorizonUIState,
2828
LGHorizonProfileOptions,
2929
LGHorizonServicesConfig,
30+
LGHorizonMediaType,
3031
)
3132
from .exceptions import (
3233
LGHorizonApiError,
@@ -70,5 +71,6 @@
7071
"LGHorizonServicesConfig",
7172
"LGHorizonRecording",
7273
"LGHorizonShowRecordingList",
74+
"LGHorizonMediaType",
7375
"COUNTRY_SETTINGS",
7476
]

lghorizon/lghorizon_device_state_processor.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
LGHorizonNDVRSource,
2020
LGHorizonReviewBufferSource,
2121
LGHorizonRecordingSource,
22+
LGHorizonMediaType,
2223
)
2324
from .lghorizon_models import LGHorizonAuth
2425
from .lghorizon_models import LGHorizonReplayEvent, LGHorizonVOD, LGHorizonVODType
@@ -124,6 +125,7 @@ async def _process_apps_state(
124125
device_state.show_title = apps_state.app_name
125126
device_state.image = apps_state.logo_path
126127
device_state.ui_state_type = LGHorizonUIStateType.APPS
128+
device_state.media_type = LGHorizonMediaType.APP
127129

128130
async def _process_linear_state(
129131
self,
@@ -145,8 +147,10 @@ async def _process_linear_state(
145147
service_path,
146148
)
147149
replay_event = LGHorizonReplayEvent(event_json)
148-
device_state.id = replay_event.event_id
149150
channel = self._channels[replay_event.channel_id]
151+
152+
device_state.media_type = LGHorizonMediaType.CHANNEL
153+
device_state.id = replay_event.event_id
150154
device_state.source_type = source.source_type
151155
device_state.channel_id = channel.id
152156
device_state.channel_name = channel.title
@@ -189,8 +193,10 @@ async def _process_reviewbuffer_state(
189193
service_path,
190194
)
191195
replay_event = LGHorizonReplayEvent(event_json)
192-
device_state.id = replay_event.event_id
193196
channel = self._channels[replay_event.channel_id]
197+
198+
device_state.media_type = LGHorizonMediaType.CHANNEL
199+
device_state.id = replay_event.event_id
194200
device_state.source_type = source.source_type
195201
device_state.channel_id = channel.id
196202
device_state.channel_name = channel.title
@@ -205,6 +211,7 @@ async def _process_reviewbuffer_state(
205211
device_state.start_time = replay_event.start_time
206212
device_state.end_time = replay_event.end_time
207213
device_state.duration = replay_event.end_time - replay_event.start_time
214+
208215
# Add random number to url to force refresh
209216
join_param = "?"
210217
if join_param in channel.stream_image:
@@ -234,9 +241,11 @@ async def _process_replay_state(
234241
service_path,
235242
)
236243
replay_event = LGHorizonReplayEvent(event_json)
237-
device_state.id = replay_event.event_id
238244
# Iets met buffer doen
239245
channel = self._channels[replay_event.channel_id]
246+
247+
device_state.media_type = LGHorizonMediaType.CHANNEL
248+
device_state.id = replay_event.event_id
240249
device_state.source_type = source.source_type
241250
device_state.channel_id = channel.id
242251
device_state.episode_title = replay_event.episode_name
@@ -279,8 +288,10 @@ async def _process_vod_state(
279288
device_state.episode_title = vod.title
280289
device_state.season_number = vod.season
281290
device_state.episode_number = vod.episode
291+
device_state.media_type = LGHorizonMediaType.EPISODE
282292
else:
283293
device_state.show_title = vod.title
294+
device_state.media_type = LGHorizonMediaType.MOVIE
284295

285296
device_state.duration = vod.duration
286297
device_state.last_position_update = int(time.time())
@@ -335,6 +346,8 @@ async def _process_ndvr_state(
335346
else:
336347
device_state.show_title = recording.show_title
337348

349+
device_state.media_type = LGHorizonMediaType.CHANNEL
350+
338351
device_state.image = await self._get_intent_image_url(recording.id)
339352

340353
async def _get_intent_image_url(self, intent_id: str) -> Optional[str]:

lghorizon/lghorizon_models.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ class LGHorizonUIStateType(Enum):
6969
UNKNOWN = "unknown"
7070

7171

72+
class LGHorizonMediaType(Enum):
73+
"""Enumeration of LG Horizon Media types"""
74+
75+
UNKNOWN = "unknown"
76+
CHANNEL = "channel"
77+
APP = "app"
78+
MOVIE = "movie"
79+
EPISODE = "episode"
80+
TVSHOW = "tvshow"
81+
82+
7283
class LGHorizonMessage(ABC):
7384
"""Abstract base class for LG Horizon messages."""
7485

@@ -869,6 +880,7 @@ class LGHorizonDeviceState:
869880
_speed: Optional[int]
870881
_start_time: Optional[int]
871882
_end_time: Optional[int]
883+
_media_type: LGHorizonMediaType
872884

873885
def __init__(self) -> None:
874886
"""Initialize the playing info."""
@@ -890,6 +902,7 @@ def __init__(self) -> None:
890902
self._id = None
891903
self._start_time = None
892904
self._end_time = None
905+
self._media_type = LGHorizonMediaType.UNKNOWN
893906

894907
@property
895908
def state(self) -> LGHorizonRunningState:
@@ -1031,6 +1044,16 @@ def ui_state_type(self, value: LGHorizonUIStateType) -> None:
10311044
"""Set the source type."""
10321045
self._ui_state_type = value
10331046

1047+
@property
1048+
def media_type(self) -> LGHorizonMediaType:
1049+
"""Return the source type."""
1050+
return self._media_type
1051+
1052+
@media_type.setter
1053+
def media_type(self, value: LGHorizonMediaType) -> None:
1054+
"""Set the source type."""
1055+
self._media_type = value
1056+
10341057
@property
10351058
def paused(self) -> bool:
10361059
"""Return if the media is paused."""
@@ -1099,6 +1122,7 @@ async def reset(self) -> None:
10991122
self.id = None
11001123
self.start_time = None
11011124
self.end_time = None
1125+
self.media_type = LGHorizonMediaType.UNKNOWN
11021126
await self.reset_progress()
11031127

11041128

0 commit comments

Comments
 (0)