sebr / bhyve-home-assistant

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

Fix timedelta attribute error #161

Closed cjsturgess closed 1 year ago

cjsturgess commented 1 year ago

This PR addresses an error raised when attempting to toggle a zone switch. Specifically, when attempting to turn a zone switch on, the error message Failed to call service switch/turn_on. 'datetime.timedelta' object has no attribute 'minutes' is raised and the zone is not turned on.

Upon inspection, I found that the error is caused on line 625 of switch.py, in which the warning log call (to indicate manual preset runtime is 0) incorrectly attempts to use DEFAULT_MANUAL_RUNTIME.minutes. As minutes is not a valid attribute of a timedelta object (DEFAULT_MANUAL_RUNTIME), the error is raised. Resolved by changing this line to int(DEFAULT_MANUAL_RUNTIME.seconds / 60).

For reference, this occurred on the following set up/versions: Home Assistant: 2022.12.9 bhyve-home-assistant: 3.0.1 (Installed via HACS) Irrigation Controller: 57950 (HW: WT25-0001, FW: 0032)

zone_switch_error