My custom switch gets immediate turn_off event after turn_on event

I’ve written my own component and corresponding switch for an irrigation controller (see: Adding a new component/switch/sensor) and it seems to be working for the most part.

Unfortunately, when I issue a turn_on event (by clicking the slider or sending an MQTT event), my turn_on handler gets called which turns on the valve but then immediately thereafter, my turn_off handler is also called. I have some _LOGGER.info()s that show the progression. I’m not sure how to tell what’s causing that. Here’s a log snippet:

2017-07-29 07:57:43 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service=turn_on, service_data=entity_id=switch.garden, service_call_id=140002364163240-15, domain=homeassistant>
2017-07-29 07:57:43 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service=turn_on, service_data=entity_id=['switch.garden'], service_call_id=140002364163240-16, domain=switch>
2017-07-29 07:57:43 INFO (Thread-22) [homeassistant.components.switch.etherrain] turn on etherrain switch 2
2017-07-29 07:57:43 INFO (Thread-22) [homeassistant.components.etherrain] Set 2 to 60 minutes
2017-07-29 07:57:43 INFO (Thread-22) [homeassistant.components.etherrain] url is http://192.168.34.4/result.cgi?xi="0:0:60:0:0:0:0:0:0
2017-07-29 07:57:43 INFO (Thread-3) [homeassistant.components.etherrain] Set 2 to 0 minutes
2017-07-29 07:57:43 INFO (Thread-3) [homeassistant.components.etherrain] url is http://192.168.34.4/result.cgi?xi="0:0:0:0:0:0:0:0:0
2017-07-29 07:57:43 INFO (Thread-3) [homeassistant.components.etherrain] valve is 2 and is ready
2017-07-29 07:57:43 INFO (Thread-3) [homeassistant.components.switch.etherrain] update etherrain switch 2 - False
2017-07-29 07:57:43 INFO (MainThread) [homeassistant.components.switch.etherrain] update etherrain switch 2 - False

Can anyone shed any light on what might be happening? Is my turn_on or turn_off handler supposed to return something specific? I don’t see others in switch/*.py returning anything…

Sigh. I figured it out.

Is there a way to remove a post? There doesn’t seem to be.

Just add what was up and leave it as info for anyone who comes across the same issue

I had a bug in my state change handler. A local non-home-assistant type bug…