1 """Support for the Twitch stream status."""
3 from __future__
import annotations
14 from .
import TwitchCoordinator
15 from .const
import DOMAIN
16 from .coordinator
import TwitchUpdate
20 ATTR_SUBSCRIPTION =
"subscribed"
21 ATTR_SUBSCRIPTION_GIFTED =
"subscription_is_gifted"
22 ATTR_SUBSCRIPTION_TIER =
"subscription_tier"
23 ATTR_FOLLOW =
"following"
24 ATTR_FOLLOW_SINCE =
"following_since"
25 ATTR_FOLLOWING =
"followers"
26 ATTR_VIEWERS =
"viewers"
27 ATTR_STARTED_AT =
"started_at"
29 STATE_OFFLINE =
"offline"
30 STATE_STREAMING =
"streaming"
38 async_add_entities: AddEntitiesCallback,
40 """Initialize entries."""
41 coordinator = hass.data[DOMAIN][entry.entry_id]
44 TwitchSensor(coordinator, channel_id)
for channel_id
in coordinator.data
49 """Representation of a Twitch channel."""
51 _attr_translation_key =
"channel"
53 def __init__(self, coordinator: TwitchCoordinator, channel_id: str) ->
None:
54 """Initialize the sensor."""
62 """Return if entity is available."""
63 return super().available
and self.
channel_idchannel_id
in self.coordinator.data
67 """Return the channel data."""
68 return self.coordinator.data[self.
channel_idchannel_id]
72 """Return the state of the sensor."""
73 return STATE_STREAMING
if self.
channelchannel.is_streaming
else STATE_OFFLINE
77 """Return the state attributes."""
80 ATTR_FOLLOWING: channel.followers,
81 ATTR_GAME: channel.game,
82 ATTR_TITLE: channel.title,
83 ATTR_STARTED_AT: channel.started_at,
84 ATTR_VIEWERS: channel.viewers,
86 resp[ATTR_SUBSCRIPTION] =
False
87 if channel.subscribed
is not None:
88 resp[ATTR_SUBSCRIPTION] = channel.subscribed
89 resp[ATTR_SUBSCRIPTION_GIFTED] = channel.subscription_gifted
90 resp[ATTR_SUBSCRIPTION_TIER] = channel.subscription_tier
91 resp[ATTR_FOLLOW] = channel.follows
93 resp[ATTR_FOLLOW_SINCE] = channel.following_since
98 """Return the picture of the sensor."""
99 if self.
channelchannel.is_streaming:
100 assert self.
channelchannel.stream_picture
is not None
101 return self.
channelchannel.stream_picture
102 return self.
channelchannel.picture
dict[str, Any] extra_state_attributes(self)
TwitchUpdate channel(self)
str|None entity_picture(self)
StateType native_value(self)
None __init__(self, TwitchCoordinator coordinator, str channel_id)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)