sebr / bhyve-home-assistant

Orbit BHyve custom component for Home Assistant
MIT License
260 stars 42 forks source link

Switches fail to initialize #217

Closed MizterB closed 1 year ago

MizterB commented 1 year ago

Describe the bug When loading the BHyve integration, an error is thrown is switches are no longer created for controlling the faucet. Diagnostic sensors load fine.

The error seems to occur because the code is expecting a watering schedule ("next start_time") to be defined for the device. I do not have a schedule defined - I water manually (typically through this integration!).

Expected behaviour A switch should be created that allows me to control the flow of the faucet.

BHyve devices

HT25-0000
by Orbit BHyve
Firmware: 0032
Hardware: HT25-0000

Device Diagnostics

2023-08-22 15:13:01.859 ERROR (MainThread) [homeassistant.components.switch] Error while setting up bhyve platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 362, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/bhyve/switch.py", line 183, in async_setup_entry
    BHyveZoneSwitch(
  File "/config/custom_components/bhyve/switch.py", line 388, in __init__
    super().__init__(hass, bhyve, device, name, icon, SwitchDeviceClass.SWITCH)
  File "/config/custom_components/bhyve/__init__.py", line 268, in __init__
    self._setup(device)
  File "/config/custom_components/bhyve/switch.py", line 420, in _setup
    ).isoformat()
      ^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'isoformat'
sebr commented 1 year ago

@MizterB Please upload your device diagnostics

MizterB commented 1 year ago

Here you go. config_entry-bhyve-a5799276bb76e228c5e4f066a9bb14ef.json.txt

fyyzer commented 1 year ago

Just wanted to confirm I'm seeing this same behavior with the HT25-0000 as well as with my HT31-0001 devices using 3.2.1 b1

pjv commented 1 year ago

Same on my HT32-0001

My lettuce died.

@sebr can you review and merge this PR which should fix this issue?

EDIT: I manually applied the patch from that PR to the bhyve custom component in my system and (after an HA restart) it did indeed fix this issue for me.

Thanks @lukemeyer.

sebr commented 1 year ago

Apologies about the extended delay on this - I've merged the PR and will do a release asap.

AndrewEAUS commented 1 year ago
        next_start_time_raw = status.get("next_start_time")
        if next_start_time_raw is not None:
            next_start_time = orbit_time_to_local_time(
                next_start_time_raw
            ).isoformat()
            next_start_programs = status.get("next_start_programs")
            self._attrs.update(
                {
                    ATTR_NEXT_START_TIME: next_start_time,
                    ATTR_NEXT_START_PROGRAMS: next_start_programs,
                }
            )