Skip to content

feat: prefer unified warning about equipment with repeated names, with context about source of equipment#126

Open
m-d-brown wants to merge 3 commits intocryptk:mainfrom
m-d-brown:collections-dupe-logging
Open

feat: prefer unified warning about equipment with repeated names, with context about source of equipment#126
m-d-brown wants to merge 3 commits intocryptk:mainfrom
m-d-brown:collections-dupe-logging

Conversation

@m-d-brown
Copy link
Copy Markdown

Not sure if you like the check being moved out of EquipmentDict. I think it's cleaner to do this explicitly in the main loop, where the caller can annotate with additional context, and I don't think it reduces safety. Happy to rework or drop if you like. Thank again for great work and amazing recent release!

Check for duplicate names in the main refresh loop. Describe that they are due to output from the OmniLogic unit itself. This will help clarify the source in downstream usage, like in Home Assistant (HA).

I personally saw messages in HA like the following and thought I had incorrectly set up the HA OmniLogic integration:

2026-04-24 20:56:23.095 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 4 items with the same name 'SolarSensor'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.636 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'Gas'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.637 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'Solar'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.638 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'Filter Pump'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.639 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'Chlorinator'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.641 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'WaterSensor'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.641 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'FlowSensor'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.

@m-d-brown m-d-brown force-pushed the collections-dupe-logging branch from bccdfa1 to 45baf41 Compare April 25, 2026 22:48
…h context about source of equipment

Check for duplicate names in the main refresh loop. Describe that they
are due to output from the OmniLogic unit itself. This will help clarify
the source in downstream usage, like in Home Assistant (HA).

I personally saw messages in HA like the following and thought I had
incorrectly set up the HA OmniLogic integration:

```
2026-04-24 20:56:23.095 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 4 items with the same name 'SolarSensor'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.636 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'Gas'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.637 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'Solar'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.638 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'Filter Pump'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.639 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'Chlorinator'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.641 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'WaterSensor'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
2026-04-24 20:56:24.641 WARNING (MainThread) [pyomnilogic_local.collections] Equipment collection contains 2 items with the same name 'FlowSensor'. Name-based lookups will return the first match. Consider using system_id-based lookups for reliability or renaming equipment to avoid duplicates.
```
@m-d-brown m-d-brown force-pushed the collections-dupe-logging branch from 45baf41 to a714424 Compare April 25, 2026 22:49
@cryptk
Copy link
Copy Markdown
Owner

cryptk commented Apr 28, 2026

Having the check for duplicates in the EquipmentDict.init means that the check for duplicates is only ever considered once, when the EquipmentDict is initially created. Putting it in the OmniLogic._update_equipment method means that it is considered on every loop, necessitating a set comprehension and a conditional branch on every loop iteration.

The performance hit is not much, but something to be mindful of.

If the concern is that the warning message doesn't make it clear that this is coming from the Omni configuration as opposed to some other cause, it seems like this is a pretty heavy-handed approach to resolving that concern when it could be as simple as just re-wording the warning message.

I think the only advantage to moving the logic to the refresh loop is that it makes it easy to put the hostname and port of the Omni in the error message, right? I'm not sure that gives enough of a benefit to justify moving all of the logic to a location that adds a set comprehension and branch to every refresh.

I would be open to a change that just re-words the warning message to something that makes it more obvious though, something with some more "people friendly" verbiage.

… to address SonarQube feedback, and remove stale line
@m-d-brown m-d-brown force-pushed the collections-dupe-logging branch from d67c35d to 2c972a9 Compare April 28, 2026 07:08
@m-d-brown
Copy link
Copy Markdown
Author

My thinking is:

  1. This yields, for the most part, a single log message that explains the situation, rather than repeating many messages.
  2. It allows clearer context because the message is produced explicitly, rather than as a side-effect of an initializer.
  3. It's possibly more efficient, because the check happens only once when equipment is being refreshed. From my read, it looks like EquipmentDicts are created often, with items being counted each time. Not sure if it's actually more efficient though.

I realize now that _update_equipment is called when update_mspconfig or update_telemetry. If you like the other benefits,

if update_mspconfig or update_telemetry:
                self._update_equipment()
if update_mspconfig:
                # do dupe name check, in a new helper method

would be more efficient.

Agreed this could also just be a different log message if you want it only to be more "people friendly".

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants