Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions homeassistant/components/fyta/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.util import dt as dt_util

from .const import (
CONF_MAX_ACCEPTABLE,
Expand Down Expand Up @@ -132,6 +133,15 @@ class FytaMeasurementSensorEntityDescription(FytaSensorEntityDescription):
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda plant: plant.battery_level,
),
FytaSensorEntityDescription(
key="last_updated",
translation_key="last_sensor_update",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sensor feels like it's more terminology of Home Assistant. What would it be in the context of Fyta? Last device update? Last plant update? I think it's better to name it to something related to Fyta that users can relate to. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment. FYTA does not seem to have a terminology for this, they rather use the names of the product (Mini, Sphere, Beam, Terrra). In the integration we should use a generic term, though.

I'm all open for suggestions. As it relates to updates from the FYTA sensor to the hub, I thought the name appropriate. It could also be device update or something similar. Plant update sounds a bit weird for me, as a plant cannot give an update... what do you think @Turtle051987 ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think last update can be sufficient in this case, if you'd ask me. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to distinguish it from the update received via the API, which generally is referred to a last update. But again, I'm open for suggestions.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI, "last update" is what they are using in the app
image
so that would be fine for me.

device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda plant: (
dt_util.as_local(plant.last_updated) if plant.last_updated else None
),
),
]

MEASUREMENT_SENSORS: Final[list[FytaMeasurementSensorEntityDescription]] = [
Expand Down
3 changes: 3 additions & 0 deletions homeassistant/components/fyta/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
"last_fertilised": {
"name": "Last fertilized"
},
"last_sensor_update": {
Comment thread
dontinelli marked this conversation as resolved.
"name": "Last sensor update"
},
"light": {
"name": "Light",
"state_attributes": {
Expand Down
102 changes: 102 additions & 0 deletions tests/components/fyta/snapshots/test_sensor.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,57 @@
'state': 'unknown',
})
# ---
# name: test_all_entities[sensor.gummibaum_last_sensor_update-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
None,
]),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.gummibaum_last_sensor_update',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': 'Last sensor update',
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
'original_icon': None,
'original_name': 'Last sensor update',
'platform': 'fyta',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'last_sensor_update',
'unique_id': 'ce5f5431554d101905d31797e1232da8-0-last_updated',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[sensor.gummibaum_last_sensor_update-state]
StateSnapshot({
'attributes': ReadOnlyDict({
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'timestamp',
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Gummibaum Last sensor update',
}),
'context': <ANY>,
'entity_id': 'sensor.gummibaum_last_sensor_update',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '2023-01-10T18:10:00+00:00',
})
# ---
# name: test_all_entities[sensor.gummibaum_light-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
Expand Down Expand Up @@ -1011,6 +1062,57 @@
'state': 'unknown',
})
# ---
# name: test_all_entities[sensor.kakaobaum_last_sensor_update-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
None,
]),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.kakaobaum_last_sensor_update',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'object_id_base': 'Last sensor update',
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
'original_icon': None,
'original_name': 'Last sensor update',
'platform': 'fyta',
'previous_unique_id': None,
'suggested_object_id': None,
'supported_features': 0,
'translation_key': 'last_sensor_update',
'unique_id': 'ce5f5431554d101905d31797e1232da8-1-last_updated',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[sensor.kakaobaum_last_sensor_update-state]
StateSnapshot({
'attributes': ReadOnlyDict({
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'timestamp',
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Kakaobaum Last sensor update',
}),
'context': <ANY>,
'entity_id': 'sensor.kakaobaum_last_sensor_update',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '2023-01-02T18:10:00+00:00',
})
# ---
# name: test_all_entities[sensor.kakaobaum_light-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
Expand Down
Loading