augustas2 / eldes

Home Assistant custom component for Eldes Alarm system
MIT License
14 stars 4 forks source link

Switch error after HA restart #11

Closed triumfas closed 2 years ago

triumfas commented 2 years ago

Not sure what it's all about, but I see an error in log after HA restart. Might be some initial check that does not go through. No issues other than that - all is working as expected.

Logger: homeassistant.components.switch
Source: custom_components/eldes_alarm/switch.py:64
Integration: Switch ([documentation](https://www.home-assistant.io/integrations/switch), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+switch%22))
First occurred: 00:04:07 (2 occurrences)
Last logged: 00:04:07

Error adding entities for domain switch with platform eldes_alarm
Error while setting up eldes_alarm platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 521, in _async_add_entity
    original_icon=entity.icon,
  File "/config/custom_components/eldes_alarm/switch.py", line 64, in icon
    return OUTPUT_ICONS_MAP[self.data["outputs"][self.entity_index].get("iconName", "ICON_1")]
KeyError: None
augustas2 commented 2 years ago

Hi, thanks for reporting the error.

It basically fails to to set icon from map. Will add a check to handle this error.

Also would be interesting to see what data you have in outputs object.

triumfas commented 2 years ago

I have switches which I pass to Google Home. Then it's easy to use Google Assistant to automate it using routines.

# Eldes switches
  - platform: template
    switches:
      google_eldes_garage:
        value_template: "{{ is_state('alarm_control_panel.garage', 'armed_away') }}"
        turn_on:
          service: script.eldes_arm_garage
        turn_off:
          service: script.eldes_disarm_garage
      google_eldes_house:
        value_template: "{{ is_state('alarm_control_panel.house', 'armed_away') }}"
        turn_on:
          service: script.eldes_arm_house
        turn_off:
          service: script.eldes_disarm_house
augustas2 commented 2 years ago

Added error handling for switch icons. You should not see any errors again, only info messages when enabled in your HA settings and if icon is missing in your output.

To get rid of info message, you should go to your Eldes App and set correct icons for automations/outputs.

Default icon for output is mdi:lightning-bolt-outline.