From f93525e0fcdd1e4412d3a9cf93ffee9aedc5a67a Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Sat, 23 Nov 2024 17:00:28 +0000 Subject: [PATCH] Add unit of measurement to translations for Mastodon (#131343) * Add unit of measurement to translations * Fix strings lint --- homeassistant/components/mastodon/sensor.py | 3 --- homeassistant/components/mastodon/strings.json | 9 ++++++--- tests/components/mastodon/snapshots/test_sensor.ambr | 9 +++------ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/mastodon/sensor.py b/homeassistant/components/mastodon/sensor.py index 12acfc04743..a7a1d40fcc4 100644 --- a/homeassistant/components/mastodon/sensor.py +++ b/homeassistant/components/mastodon/sensor.py @@ -35,21 +35,18 @@ ENTITY_DESCRIPTIONS = ( MastodonSensorEntityDescription( key="followers", translation_key="followers", - native_unit_of_measurement="accounts", state_class=SensorStateClass.TOTAL, value_fn=lambda data: data.get(ACCOUNT_FOLLOWERS_COUNT), ), MastodonSensorEntityDescription( key="following", translation_key="following", - native_unit_of_measurement="accounts", state_class=SensorStateClass.TOTAL, value_fn=lambda data: data.get(ACCOUNT_FOLLOWING_COUNT), ), MastodonSensorEntityDescription( key="posts", translation_key="posts", - native_unit_of_measurement="posts", state_class=SensorStateClass.TOTAL, value_fn=lambda data: data.get(ACCOUNT_STATUSES_COUNT), ), diff --git a/homeassistant/components/mastodon/strings.json b/homeassistant/components/mastodon/strings.json index fb51d866642..c6aefefca06 100644 --- a/homeassistant/components/mastodon/strings.json +++ b/homeassistant/components/mastodon/strings.json @@ -42,13 +42,16 @@ "entity": { "sensor": { "followers": { - "name": "Followers" + "name": "Followers", + "unit_of_measurement": "accounts" }, "following": { - "name": "Following" + "name": "Following", + "unit_of_measurement": "[%key:component::mastodon::entity::sensor::followers::unit_of_measurement%]" }, "posts": { - "name": "Posts" + "name": "Posts", + "unit_of_measurement": "posts" } } } diff --git a/tests/components/mastodon/snapshots/test_sensor.ambr b/tests/components/mastodon/snapshots/test_sensor.ambr index c8df8cdab19..3e6e41796f6 100644 --- a/tests/components/mastodon/snapshots/test_sensor.ambr +++ b/tests/components/mastodon/snapshots/test_sensor.ambr @@ -31,7 +31,7 @@ 'supported_features': 0, 'translation_key': 'followers', 'unique_id': 'trwnh_mastodon_social_followers', - 'unit_of_measurement': 'accounts', + 'unit_of_measurement': None, }) # --- # name: test_sensors[sensor.mastodon_trwnh_mastodon_social_followers-state] @@ -39,7 +39,6 @@ 'attributes': ReadOnlyDict({ 'friendly_name': 'Mastodon @trwnh@mastodon.social Followers', 'state_class': , - 'unit_of_measurement': 'accounts', }), 'context': , 'entity_id': 'sensor.mastodon_trwnh_mastodon_social_followers', @@ -81,7 +80,7 @@ 'supported_features': 0, 'translation_key': 'following', 'unique_id': 'trwnh_mastodon_social_following', - 'unit_of_measurement': 'accounts', + 'unit_of_measurement': None, }) # --- # name: test_sensors[sensor.mastodon_trwnh_mastodon_social_following-state] @@ -89,7 +88,6 @@ 'attributes': ReadOnlyDict({ 'friendly_name': 'Mastodon @trwnh@mastodon.social Following', 'state_class': , - 'unit_of_measurement': 'accounts', }), 'context': , 'entity_id': 'sensor.mastodon_trwnh_mastodon_social_following', @@ -131,7 +129,7 @@ 'supported_features': 0, 'translation_key': 'posts', 'unique_id': 'trwnh_mastodon_social_posts', - 'unit_of_measurement': 'posts', + 'unit_of_measurement': None, }) # --- # name: test_sensors[sensor.mastodon_trwnh_mastodon_social_posts-state] @@ -139,7 +137,6 @@ 'attributes': ReadOnlyDict({ 'friendly_name': 'Mastodon @trwnh@mastodon.social Posts', 'state_class': , - 'unit_of_measurement': 'posts', }), 'context': , 'entity_id': 'sensor.mastodon_trwnh_mastodon_social_posts',