Common unit-of-measurement config for all entities #773
Unanswered
rianadon
asked this question in
Entity Models
Replies: 1 comment 1 reply
-
I would suggest to start with implementing unit conversion support specifically for Avoiding duplicating common helpers which are now part of Maybe a mixin class for Entity which adds boiler plate code for entity registry entry options? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It's been a long time since home-assistant/core#59533 fell through. Sorry about that—life got busy. I'm now brainstorming how to best approach the original goal of making weather units customizable & consistent across integrations.
Looking at https://github.com/home-assistant/core/pull/64366/files, the easiest approach seems to be:
[pressure, wind speed, precipitation, ...]
CONF_UNITS_OF_MEASUREMENT
setting to the entity registry. This will be a dictionary of fields likepressure: hPa
def state(self)
incomponents/weather/__init__.py
However, I will be duplicating some of the supporting code (e.g. listening for entity registry updates, rendering the units options on the frontend). Other entities with user-configurable units will also need to duplicate similar code. Some options for consolidation I'm considering:
Pull out some useful unit conversion routines like scaling units and suppressing ValueErrors from
sensor/__init__.py
and put them in theutils
libraries.(I don't like this) Make
CONF_UNITS_OF_MEASUREMENTS
standardized across all entities, includingsensor
. In the frontend, this might look like a second drop-down where 1 or more units of measurement could be configured.This is keeps the units of the measurement in a consistent spot, but I'm unsure if having a dropdown makes sense for cases where there's only one unit of measurement to configure.
(I like this better) I'm also considering a system where entities have either a
CONF_UNIT_OF_MEASUREMENTS
option rendered as an input field or aCONF_UNITS_OF_MEASUREMENTS
option rendered as a dropdown.Also one lingering question: I remember the effect of the user changing units on the history graphs was an issue in previous discussions. Is there a solution to this problem?
@emontnemery @frenck you've both had great advice in my last PRs on the weather integration units so I'm curious to hear your opinion on this.
Beta Was this translation helpful? Give feedback.
All reactions