mirror of
https://github.com/home-assistant/core.git
synced 2025-07-04 11:57:05 +00:00
YouTube Component - Enable SensorStateClass for Long Term Statistic Support (#142670)
* Youtube Component Support SensorStateClass in sensor.py Added support for long term statistics by including the appropriate state class type for subscriber and view counts. * Update sensor.py * Fix --------- Co-authored-by: Joostlek <joostlek@outlook.com>
This commit is contained in:
parent
c4485c1814
commit
c36f8c38ae
@ -6,7 +6,11 @@ from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
||||
from homeassistant.components.sensor import (
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ICON
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -54,6 +58,7 @@ SENSOR_TYPES = [
|
||||
key="subscribers",
|
||||
translation_key="subscribers",
|
||||
native_unit_of_measurement="subscribers",
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
available_fn=lambda _: True,
|
||||
value_fn=lambda channel: channel[ATTR_SUBSCRIBER_COUNT],
|
||||
entity_picture_fn=lambda channel: channel[ATTR_ICON],
|
||||
@ -63,6 +68,7 @@ SENSOR_TYPES = [
|
||||
key="views",
|
||||
translation_key="views",
|
||||
native_unit_of_measurement="views",
|
||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||
available_fn=lambda _: True,
|
||||
value_fn=lambda channel: channel[ATTR_TOTAL_VIEWS],
|
||||
entity_picture_fn=lambda channel: channel[ATTR_ICON],
|
||||
|
@ -20,6 +20,7 @@
|
||||
'attributes': ReadOnlyDict({
|
||||
'entity_picture': 'https://yt3.ggpht.com/fca_HuJ99xUxflWdex0XViC3NfctBFreIl8y4i9z411asnGTWY-Ql3MeH_ybA4kNaOjY7kyA=s800-c-k-c0x00ffffff-no-rj',
|
||||
'friendly_name': 'Google for Developers Subscribers',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': 'subscribers',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
@ -35,6 +36,7 @@
|
||||
'attributes': ReadOnlyDict({
|
||||
'entity_picture': 'https://yt3.ggpht.com/fca_HuJ99xUxflWdex0XViC3NfctBFreIl8y4i9z411asnGTWY-Ql3MeH_ybA4kNaOjY7kyA=s800-c-k-c0x00ffffff-no-rj',
|
||||
'friendly_name': 'Google for Developers Views',
|
||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
'unit_of_measurement': 'views',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
@ -63,6 +65,7 @@
|
||||
'attributes': ReadOnlyDict({
|
||||
'entity_picture': 'https://yt3.ggpht.com/fca_HuJ99xUxflWdex0XViC3NfctBFreIl8y4i9z411asnGTWY-Ql3MeH_ybA4kNaOjY7kyA=s800-c-k-c0x00ffffff-no-rj',
|
||||
'friendly_name': 'Google for Developers Subscribers',
|
||||
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
|
||||
'unit_of_measurement': 'subscribers',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
@ -78,6 +81,7 @@
|
||||
'attributes': ReadOnlyDict({
|
||||
'entity_picture': 'https://yt3.ggpht.com/fca_HuJ99xUxflWdex0XViC3NfctBFreIl8y4i9z411asnGTWY-Ql3MeH_ybA4kNaOjY7kyA=s800-c-k-c0x00ffffff-no-rj',
|
||||
'friendly_name': 'Google for Developers Views',
|
||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
'unit_of_measurement': 'views',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user