diff --git a/homeassistant/components/youtube/sensor.py b/homeassistant/components/youtube/sensor.py index 128c23f7082..224ace3d405 100644 --- a/homeassistant/components/youtube/sensor.py +++ b/homeassistant/components/youtube/sensor.py @@ -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], diff --git a/tests/components/youtube/snapshots/test_sensor.ambr b/tests/components/youtube/snapshots/test_sensor.ambr index f4549e89c8c..feddd644cee 100644 --- a/tests/components/youtube/snapshots/test_sensor.ambr +++ b/tests/components/youtube/snapshots/test_sensor.ambr @@ -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': , 'unit_of_measurement': 'subscribers', }), 'context': , @@ -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': , 'unit_of_measurement': 'views', }), 'context': , @@ -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': , 'unit_of_measurement': 'subscribers', }), 'context': , @@ -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': , 'unit_of_measurement': 'views', }), 'context': ,