Skip to content
Snippets Groups Projects
Commit 9418c61b authored by Klaas Hoekema's avatar Klaas Hoekema Committed by Pascal Vizeli
Browse files

Use feed name assigned in EmonCMS if there is one (#10021)

The default names for the feeds created by the EmonCMS component are
like 'emoncms1_feedid_10', but
- This is the display name. The ID should be lowercase and underscored,
  but the display name should be readable. The ID gets derived from it
  and comes out formatted correctly.
- EmonCMS lets you assign names to feeds, so it makes sense to use those
  if they exist, rather than feed IDs. The ID is pretty meaningless and
  basically means you have to override every name to make it readable.
- Including the ID identifying the EmonCMS instance (i.e. the '1') makes
  the name clunkier and would only be useful for people with multiple
  EmonCMS instances, which is likely to be an extremely small group since
  one hub can run as many feeds as you need it to.

This changes the default behavior but still uses configured 'name' if
it's set, so it won't break the configuration of people who have
customized their feed names in HA config.
parent 62caea6b
Branches
Tags
No related merge requests found
...@@ -112,8 +112,13 @@ class EmonCmsSensor(Entity): ...@@ -112,8 +112,13 @@ class EmonCmsSensor(Entity):
unit_of_measurement, sensorid, elem): unit_of_measurement, sensorid, elem):
"""Initialize the sensor.""" """Initialize the sensor."""
if name is None: if name is None:
self._name = "emoncms{}_feedid_{}".format( # Suppress ID in sensor name if it's 1, since most people won't
sensorid, elem["id"]) # have more than one EmonCMS source and it's redundant to show the
# ID if there's only one.
id_for_name = '' if str(sensorid) == '1' else sensorid
# Use the feed name assigned in EmonCMS or fall back to the feed ID
feed_name = elem.get('name') or 'Feed {}'.format(elem['id'])
self._name = "EmonCMS{} {}".format(id_for_name, feed_name)
else: else:
self._name = name self._name = name
self._identifier = get_id( self._identifier = get_id(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment