Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

feat: support sensors which are timestamps (like uptime sensor) #677

Merged
merged 3 commits into from
Mar 29, 2021

Conversation

akloeckner
Copy link
Contributor

  • use the default filter option for sensors
  • parse with timeAgo in case we have a timestamp
  • include the word ago, because timestamps are indeed ago
  • add hint how to exclude the word ago for the uptime sensor

Localization should be handled separately, and globally for all places where moment is used.
In order to allow the user to profit from this further localization, moment() should be then be made available by utils.js.

closes #671

* use the default `filter` option for sensors
* parse with `timeAgo` in case we have a timestamp
* include the word `ago`, because timestamps are indeed ago
* add hint how to exclude the word `ago` for the uptime sensor

Localization should be handled separately, and globally for all places where `moment` is used.
In order to allow the user to profit from this further localization, `moment()` should be then be made available by `utils.js`.

closes resoai#671
scripts/globals/utils.js Outdated Show resolved Hide resolved
scripts/globals/utils.js Outdated Show resolved Hide resolved
Comment on lines +453 to +455
if (entity?.attributes?.device_class === 'timestamp') {
return timeAgo(value, false);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just thinking aloud but I was wondering if device_class === timestamp implies that it's the "uptime" type of sensor? Because that change might not make sense for sensors other than uptime types.

But since I don't know the cases where those sensors are used, I won't argue with it and assume that it's a good default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We didn't want to argue. :-) Still...

I have not found any other standard HA integration with timestamp device class. So, uptime seems to be the most common use case.

However, there are people using custom sensors, such as "last time that file changed". Also for those sensors, timeAgo is a decent default for a dashboard display.

Then, there might be power users that really want to see the actual timestamp. They would have to change the filter then.

@rchl rchl changed the title feat: support sensors which are timestamps (notably the uptime sensor) feat: support sensors which are timestamps (like uptime sensor) Mar 29, 2021
@rchl rchl merged commit b417812 into resoai:master Mar 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for timestamps
2 participants