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

KeyError: <Platform.SELECT: 'select'> #74

Open
onurece opened this issue Jan 31, 2025 · 2 comments
Open

KeyError: <Platform.SELECT: 'select'> #74

onurece opened this issue Jan 31, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@onurece
Copy link

onurece commented Jan 31, 2025

Hi,

I'm using SLR1b with a Hive thermostat to control my boiler.

I've noticed in HA logs that very often I'm getting error messages like below.

2025-01-31 00:46:29.625 ERROR (MainThread) [homeassistant.util.logging] Exception in mqtt_message_received when handling msg on 'zigbee2mqtt/Hive Receiver': '{"linkquality":58,"local_temperature":20.58,"occupied_heating_setpoint":15,"running_state":"idle","system_mode":"heat","temperature_setpoint_hold":true,"temperature_setpoint_hold_duration":65535}'
Traceback (most recent call last):
  File "/config/custom_components/hive_local_thermostat/__init__.py", line 81, in mqtt_message_received
    for entity in hass.data[DOMAIN][entry.entry_id][platform]:
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: <Platform.SELECT: 'select'>

I did a bit investigation and I think I have an idea why this is happening.
Here the value of PLATFORMS is as below
[<Platform.SENSOR: 'sensor'>, <Platform.CLIMATE: 'climate'>, <Platform.NUMBER: 'number'>, <Platform.SELECT: 'select'>, <Platform.BUTTON: 'button'>, <Platform.BINARY_SENSOR: 'binary_sensor'>]
However, my hass.data[DOMAIN][entry.entry_id] doesn't have <Platform.SELECT: 'select'>. It only has the below
{'entities': [], <Platform.SENSOR: 'sensor'>: [<entity sensor.hive_receiver_running_state_heat=idle>, <entity sensor.hive_receiver_current_temperature=20.6>, <entity sensor.hive_receiver_heating_boost_remaining=unknown>], <Platform.CLIMATE: 'climate'>: [<entity climate.hive_receiver_climate=heat>], 'heating_boost_duration': 120, 'heating_frost_prevention': 12, 'heating_default_temperature': 20, 'heating_boost_temperature': 25, <Platform.NUMBER: 'number'>: [<entity number.hive_receiver_heating_boost_duration=120>, <entity number.hive_receiver_heating_frost_prevention=12>, <entity number.hive_receiver_heating_default_temperature=20>, <entity number.hive_receiver_heating_boost_temperature=25>], <Platform.BUTTON: 'button'>: [<entity button.hive_receiver_heating_boost=unknown>], <Platform.BINARY_SENSOR: 'binary_sensor'>: [<entity binary_sensor.hive_receiver_heating_boost=unknown>]}

As there's no <Platform.SELECT: 'select'> in that dictionary, I get the KeyError.

Then, I looked a bit more into why I don't have <Platform.SELECT: 'select'>. I believe it's because I don't have a SELECT entity created.
Image

Then, I checked what happens to select entities here. If I'm not mistaken, this is something only used with hot water, but my boiler, thus my receiver, doesn't have anything to do with hot water.

So, to solve this I think a simple check to see if platform exists in hass.data[DOMAIN][entry.entry_id][platform] in here should suffice like below

for platform in PLATFORMS:
    if platform in hass.data[DOMAIN][entry.entry_id]:
        for entity in hass.data[DOMAIN][entry.entry_id][platform]:
            entity.process_update(parsed_data)

Or
The solution could be to remove Platform.SELECT in here for SLR1 devices as they don't have hot water, but only SLR2 do as described here.

I can create a fork and do the first one, but not sure how to implement the second solution.

What do you think? Is this the correct root cause?

I'm surprised that this hasn't been raised before. Maybe it's because most important functions, namely Platform.SENSOR, Platform.CLIMATE, Platform.NUMBER, which happen to be before Platform.SELECT in this list are working fine.

@andrew-codechimp andrew-codechimp self-assigned this Jan 31, 2025
@andrew-codechimp andrew-codechimp added the bug Something isn't working label Jan 31, 2025
@andrew-codechimp
Copy link
Owner

Hi, thanks for reporting this. I have an SRL2 so didn't see this issue.
You are right with your suggestions, I'll just need to build some conditionals around the platforms.
It won't hurt but I hate log errors as much as anyone so will work on a fix.

@onurece
Copy link
Author

onurece commented Jan 31, 2025

Thanks! Let me know if you need any help testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants