Cleanup climate platform for async update_ha_state / migrate generic thermostat (#5679)

* Cleanup climate from blocking stuff / migrate generic

* Migrate generic thermostat

* fix tests

* fix lint
This commit is contained in:
Pascal Vizeli authored and Paulus Schoutsen committed 2017-02-01 21:44:05 -08:00
1 parent 647a93801c
commit 10a104271e
8 files changed
+79 -49

No files matched your search

+23 -3
View File
@@ -11,6 +11,7 @@ import os
import voluptuous as vol
from homeassistant.core import callback
from homeassistant.config import load_yaml_config_file
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.entity import ToggleEntity
@@ -20,6 +21,7 @@ from homeassistant.const import (
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE,
ATTR_ENTITY_ID)
from homeassistant.components import group
from homeassistant.util.async import run_callback_threadsafe
DOMAIN = 'switch'
SCAN_INTERVAL = timedelta(seconds=30)
@@ -47,21 +49,39 @@ _LOGGER = logging.getLogger(__name__)
def is_on(hass, entity_id=None):
"""Return if the switch is on based on the statemachine."""
"""Return if the switch is on based on the statemachine.
Async friendly.
"""
entity_id = entity_id or ENTITY_ID_ALL_SWITCHES
return hass.states.is_state(entity_id, STATE_ON)
def turn_on(hass, entity_id=None):
"""Turn all or specified switch on."""
run_callback_threadsafe(
hass.loop, async_turn_on, hass, entity_id).result()
@callback
def async_turn_on(hass, entity_id=None):
"""Turn all or specified switch on."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data))
def turn_off(hass, entity_id=None):
"""Turn all or specified switch off."""
run_callback_threadsafe(
hass.loop, async_turn_off, hass, entity_id).result()
@callback
def async_turn_off(hass, entity_id=None):
"""Turn all or specified switch off."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
hass.async_add_job(
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF, data))
def toggle(hass, entity_id=None):