Fix thread termination on exit.

This commit is contained in:
pavoni committed 2016-04-01 15:36:33 +01:00
1 parent 5aa04de006
commit 6ee086c0bb
4 files changed
+14 -6

No files matched your search

@@ -7,12 +7,13 @@ https://home-assistant.io/components/sensor.loop_energy/
import logging
from homeassistant.helpers.entity import Entity
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
_LOGGER = logging.getLogger(__name__)
DOMAIN = "loopenergy"
REQUIREMENTS = ['pyloopenergy==0.0.4']
REQUIREMENTS = ['pyloopenergy==0.0.5']
def setup_platform(hass, config, add_devices, discovery_info=None):
@@ -45,6 +46,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
gas_secret
)
def stop_loopenergy(event):
"""Shutdown loopenergy thread on exit."""
_LOGGER.info("Shutting down loopenergy.")
controller.terminate()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_loopenergy)
sensors = [LoopEnergyElec(controller)]
if gas_serial: