Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integral helper falsely only allows selecting sensors with "unit_of_measurement": null after previous sensor (with non-null unit_of_measurement) got deleted #131389

Open
laundmo opened this issue Nov 23, 2024 · 1 comment

Comments

@laundmo
Copy link

laundmo commented Nov 23, 2024

The problem

After a sensor which was previously used in a Integral helper was removed, i tried to modify this integral to add the replacement for the now-removed sensor. This led to an error since i think i'm only allowed to enter sensors which have the same "unit_of_measurement" as the previous sensor, which is null due to the previous sensor being deleted. Entering the sensor anyways, even though it doesn't appear in the dropdown, causes this error (from which i've removed some sensors):

value must be one of ['sensor.sun_next_dawn', 'sensor.sun_next_dusk', 'sensor.sun_next_midnight', 'sensor.sun_next_noon', 'sensor.sun_next_rising', 'sensor.sun_next_setting']

all the sensors in this error happen to have a unit_of_measurement of null in /config/.storage/core.entity_registry

I'm pretty sure this snippet is the source of this issue, as it seems to do exactly that filtering for the same unit of measurement:

def entity_selector_compatible(
handler: SchemaOptionsFlowHandler,
) -> selector.EntitySelector:
"""Return an entity selector which compatible entities."""
current = handler.hass.states.get(handler.options[CONF_SOURCE_SENSOR])
unit_of_measurement = (
current.attributes.get(ATTR_UNIT_OF_MEASUREMENT) if current else None
)
entities = [
ent.entity_id
for ent in handler.hass.states.async_all(ALLOWED_DOMAINS)
if ent.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == unit_of_measurement
and ent.domain in ALLOWED_DOMAINS
]
return selector.EntitySelector(
selector.EntitySelectorConfig(include_entities=entities)
)

I think a solution could be to not filter at all after a sensor is delted, or alternatively to store the required unit of measurement on the Integral helper.

What version of Home Assistant Core has the issue?

2024.11.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Integral

Link to integration documentation on our website

https://www.home-assistant.io/integrations/integration

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

/config/.storage/core.config_entries of the integral helper

{
  "created_at": "1970-01-01T00:00:00+00:00",
  "data": {},
  "discovery_keys": {},
  "disabled_by": null,
  "domain": "integration",
  "entry_id": "REDACTED",
  "minor_version": 1,
  "modified_at": "1970-01-01T00:00:00+00:00",
  "options": {
    "name": "REDACTED",
    "unit_time": "h",
    "source": "sensor.REDACTED",
    "method": "left"
  },
  "pref_disable_new_entities": false,
  "pref_disable_polling": false,
  "source": "user",
  "title": "REDACTED",
  "unique_id": null,
  "version": 1
}

/config/.storage/core.entity_registry of "sensor.REDACTED"

"deleted_entities":[
  {
	"config_entry_id":"REDACTED",
	"created_at":"1970-01-01T00:00:00+00:00",
	"entity_id":"sensor.REDACTED",
	"id":"REDACTED",
	"modified_at":"2024-11-23T17:00:03.533295+00:00",
	"orphaned_timestamp":null,
	"platform":"REDACTED",
	"unique_id":"REDACTED"
  },
]
@home-assistant
Copy link

Hey there @dgomes, mind taking a look at this issue as it has been labeled with an integration (integration) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of integration can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign integration Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


integration documentation
integration source
(message by IssueLinks)

@laundmo laundmo changed the title Integral helper only allows selecting sensors with "unit_of_measurement": null when previous sensor is deleted Integral helper falsely only allows selecting sensors with "unit_of_measurement": null after previous sensor (with non-null unit_of_measurement) got deleted Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants