mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Make Twitch sensor state and attributes translatable (#133127)
This commit is contained in:
parent
81c8d7153b
commit
d658073246
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -49,6 +49,8 @@ class TwitchSensor(CoordinatorEntity[TwitchCoordinator], SensorEntity):
|
|||||||
"""Representation of a Twitch channel."""
|
"""Representation of a Twitch channel."""
|
||||||
|
|
||||||
_attr_translation_key = "channel"
|
_attr_translation_key = "channel"
|
||||||
|
_attr_device_class = SensorDeviceClass.ENUM
|
||||||
|
_attr_options = [STATE_OFFLINE, STATE_STREAMING]
|
||||||
|
|
||||||
def __init__(self, coordinator: TwitchCoordinator, channel_id: str) -> None:
|
def __init__(self, coordinator: TwitchCoordinator, channel_id: str) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
@ -82,8 +84,8 @@ class TwitchSensor(CoordinatorEntity[TwitchCoordinator], SensorEntity):
|
|||||||
ATTR_TITLE: channel.title,
|
ATTR_TITLE: channel.title,
|
||||||
ATTR_STARTED_AT: channel.started_at,
|
ATTR_STARTED_AT: channel.started_at,
|
||||||
ATTR_VIEWERS: channel.viewers,
|
ATTR_VIEWERS: channel.viewers,
|
||||||
|
ATTR_SUBSCRIPTION: False,
|
||||||
}
|
}
|
||||||
resp[ATTR_SUBSCRIPTION] = False
|
|
||||||
if channel.subscribed is not None:
|
if channel.subscribed is not None:
|
||||||
resp[ATTR_SUBSCRIPTION] = channel.subscribed
|
resp[ATTR_SUBSCRIPTION] = channel.subscribed
|
||||||
resp[ATTR_SUBSCRIPTION_GIFTED] = channel.subscription_gifted
|
resp[ATTR_SUBSCRIPTION_GIFTED] = channel.subscription_gifted
|
||||||
|
@ -16,5 +16,47 @@
|
|||||||
"oauth_unauthorized": "[%key:common::config_flow::abort::oauth2_unauthorized%]",
|
"oauth_unauthorized": "[%key:common::config_flow::abort::oauth2_unauthorized%]",
|
||||||
"oauth_failed": "[%key:common::config_flow::abort::oauth2_failed%]"
|
"oauth_failed": "[%key:common::config_flow::abort::oauth2_failed%]"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"entity": {
|
||||||
|
"sensor": {
|
||||||
|
"channel": {
|
||||||
|
"state": {
|
||||||
|
"streaming": "Streaming",
|
||||||
|
"offline": "Offline"
|
||||||
|
},
|
||||||
|
"state_attributes": {
|
||||||
|
"followers": {
|
||||||
|
"name": "Followers"
|
||||||
|
},
|
||||||
|
"game": {
|
||||||
|
"name": "Game"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"name": "Title"
|
||||||
|
},
|
||||||
|
"started_at": {
|
||||||
|
"name": "Started at"
|
||||||
|
},
|
||||||
|
"viewers": {
|
||||||
|
"name": "Viewers"
|
||||||
|
},
|
||||||
|
"subscribed": {
|
||||||
|
"name": "Subscribed"
|
||||||
|
},
|
||||||
|
"subscription_is_gifted": {
|
||||||
|
"name": "Subscription is gifted"
|
||||||
|
},
|
||||||
|
"subscription_tier": {
|
||||||
|
"name": "Subscription tier"
|
||||||
|
},
|
||||||
|
"following": {
|
||||||
|
"name": "Following"
|
||||||
|
},
|
||||||
|
"following_since": {
|
||||||
|
"name": "Following since"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user