1 """Support for interfacing with an instance of getchannels.com."""
3 from __future__
import annotations
7 from pychannels
import Channels
8 import voluptuous
as vol
11 PLATFORM_SCHEMA
as MEDIA_PLAYER_PLATFORM_SCHEMA,
13 MediaPlayerEntityFeature,
23 from .const
import SERVICE_SEEK_BACKWARD, SERVICE_SEEK_BY, SERVICE_SEEK_FORWARD
25 DATA_CHANNELS =
"channels"
26 DEFAULT_NAME =
"Channels"
29 PLATFORM_SCHEMA = MEDIA_PLAYER_PLATFORM_SCHEMA.extend(
31 vol.Required(CONF_HOST): cv.string,
32 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
33 vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
41 async_add_entities: AddEntitiesCallback,
42 discovery_info: DiscoveryInfoType |
None =
None,
44 """Set up the Channels platform."""
45 device =
ChannelsPlayer(config[CONF_NAME], config[CONF_HOST], config[CONF_PORT])
48 platform = entity_platform.async_get_current_platform()
50 platform.async_register_entity_service(
55 platform.async_register_entity_service(
56 SERVICE_SEEK_BACKWARD,
60 platform.async_register_entity_service(
62 {vol.Required(ATTR_SECONDS): vol.Coerce(int)},
68 """Representation of a Channels instance."""
70 _attr_media_content_type = MediaType.CHANNEL
71 _attr_supported_features = (
72 MediaPlayerEntityFeature.PLAY
73 | MediaPlayerEntityFeature.PAUSE
74 | MediaPlayerEntityFeature.STOP
75 | MediaPlayerEntityFeature.VOLUME_MUTE
76 | MediaPlayerEntityFeature.NEXT_TRACK
77 | MediaPlayerEntityFeature.PREVIOUS_TRACK
78 | MediaPlayerEntityFeature.PLAY_MEDIA
79 | MediaPlayerEntityFeature.SELECT_SOURCE
83 """Initialize the Channels app."""
108 """Update the favorite channels from the client."""
112 """Update all the state properties with the passed in dictionary."""
113 self.
statusstatus = state_hash.get(
"status",
"stopped")
114 self.
mutedmuted = state_hash.get(
"muted",
False)
116 channel_hash = state_hash.get(
"channel")
117 np_hash = state_hash.get(
"now_playing")
120 self.
channel_numberchannel_number = channel_hash.get(
"channel_number")
121 self.
channel_namechannel_name = channel_hash.get(
"channel_name")
145 """Return the name of the player."""
146 return self.
_name_name
149 def state(self) -> MediaPlayerState | None:
150 """Return the state of the player."""
151 if self.
statusstatus ==
"stopped":
152 return MediaPlayerState.IDLE
154 if self.
statusstatus ==
"paused":
155 return MediaPlayerState.PAUSED
157 if self.
statusstatus ==
"playing":
158 return MediaPlayerState.PLAYING
163 """Retrieve latest state."""
169 """List of favorite channels."""
174 """Boolean if volume is currently muted."""
175 return self.
mutedmuted
179 """Content ID of current playing channel."""
184 """Image url of current playing media."""
190 return "https://getchannels.com/assets/img/icon-1024.png"
194 """Title of current playing media."""
201 """Mute (true) or unmute (false) player."""
202 if mute != self.
mutedmuted:
203 response = self.
clientclient.toggle_muted()
207 """Send media_stop command to player."""
208 self.
statusstatus =
"stopped"
209 response = self.
clientclient.stop()
213 """Send media_play command to player."""
214 response = self.
clientclient.resume()
218 """Send media_pause command to player."""
219 response = self.
clientclient.pause()
224 response = self.
clientclient.skip_forward()
229 response = self.
clientclient.skip_backward()
233 """Select a channel to tune to."""
235 if channel[
"name"] == source:
236 response = self.
clientclient.play_channel(channel[
"number"])
241 self, media_type: MediaType | str, media_id: str, **kwargs: Any
243 """Send the play_media command to the player."""
244 if media_type == MediaType.CHANNEL:
245 response = self.
clientclient.play_channel(media_id)
247 elif media_type
in {MediaType.MOVIE, MediaType.EPISODE, MediaType.TVSHOW}:
248 response = self.
clientclient.play_recording(media_id)
252 """Seek forward in the timeline."""
257 """Seek backward in the timeline."""
262 """Seek backward in the timeline."""
263 response = self.
clientclient.seek(seconds)