Make Twitch sensor state and attributes translatable (#133127)

This commit is contained in:
Jan-Philipp Benecke 2024-12-13 13:01:55 +01:00 committed by GitHub
parent 81c8d7153b
commit d658073246
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 2 deletions

View File

@ -4,7 +4,7 @@ from __future__ import annotations
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.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -49,6 +49,8 @@ class TwitchSensor(CoordinatorEntity[TwitchCoordinator], SensorEntity):
"""Representation of a Twitch 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:
"""Initialize the sensor."""
@ -82,8 +84,8 @@ class TwitchSensor(CoordinatorEntity[TwitchCoordinator], SensorEntity):
ATTR_TITLE: channel.title,
ATTR_STARTED_AT: channel.started_at,
ATTR_VIEWERS: channel.viewers,
ATTR_SUBSCRIPTION: False,
}
resp[ATTR_SUBSCRIPTION] = False
if channel.subscribed is not None:
resp[ATTR_SUBSCRIPTION] = channel.subscribed
resp[ATTR_SUBSCRIPTION_GIFTED] = channel.subscription_gifted

View File

@ -16,5 +16,47 @@
"oauth_unauthorized": "[%key:common::config_flow::abort::oauth2_unauthorized%]",
"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"
}
}
}
}
}
}