Fix errors in ESPHome integration (#20048)

* Fix Home Assistant State Import

* Fix cover state

* Fix fan supported features

* Fix typo
This commit is contained in:
Otto Winter 2019-01-13 15:52:23 +01:00 committed by Martin Hjelmare
parent aae6ff830a
commit 2339cb05ad
3 changed files with 12 additions and 13 deletions

View File

@ -8,7 +8,6 @@ from homeassistant.components.cover import CoverDevice, SUPPORT_CLOSE, \
from homeassistant.components.esphome import EsphomeEntity, \ from homeassistant.components.esphome import EsphomeEntity, \
platform_async_setup_entry platform_async_setup_entry
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_CLOSED, STATE_OPEN
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
if TYPE_CHECKING: if TYPE_CHECKING:
@ -33,12 +32,6 @@ async def async_setup_entry(hass: HomeAssistantType,
) )
COVER_STATE_INT_TO_STR = {
0: STATE_OPEN,
1: STATE_CLOSED
}
class EsphomeCover(EsphomeEntity, CoverDevice): class EsphomeCover(EsphomeEntity, CoverDevice):
"""A cover implementation for ESPHome.""" """A cover implementation for ESPHome."""
@ -65,7 +58,7 @@ class EsphomeCover(EsphomeEntity, CoverDevice):
"""Return if the cover is closed or not.""" """Return if the cover is closed or not."""
if self._state is None: if self._state is None:
return None return None
return COVER_STATE_INT_TO_STR[self._state.state] return bool(self._state.state)
async def async_open_cover(self, **kwargs) -> None: async def async_open_cover(self, **kwargs) -> None:
"""Open the cover.""" """Open the cover."""

View File

@ -10,7 +10,7 @@ from homeassistant import const
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, \ from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, \
EVENT_HOMEASSISTANT_STOP EVENT_HOMEASSISTANT_STOP
from homeassistant.core import callback, Event from homeassistant.core import callback, Event, State
import homeassistant.helpers.device_registry as dr import homeassistant.helpers.device_registry as dr
from homeassistant.exceptions import TemplateError from homeassistant.exceptions import TemplateError
from homeassistant.helpers import template from homeassistant.helpers import template
@ -208,11 +208,11 @@ async def async_setup_entry(hass: HomeAssistantType,
domain, service_name, service_data, blocking=True)) domain, service_name, service_data, blocking=True))
async def send_home_assistant_state(entity_id: str, _, async def send_home_assistant_state(entity_id: str, _,
new_state: Optional[str]) -> None: new_state: Optional[State]) -> None:
"""Forward Home Assistant states to ESPHome.""" """Forward Home Assistant states to ESPHome."""
if new_state is None: if new_state is None:
return return
await cli.send_home_assistant_state(entity_id, new_state) await cli.send_home_assistant_state(entity_id, new_state.state)
@callback @callback
def async_on_state_subscription(entity_id: str) -> None: def async_on_state_subscription(entity_id: str) -> None:
@ -481,7 +481,7 @@ class EsphomeEntity(Entity):
self._remove_callbacks.append( self._remove_callbacks.append(
async_dispatcher_connect(self.hass, async_dispatcher_connect(self.hass,
DISPATCHER_REMOVE_ENTITY.format(**kwargs), DISPATCHER_REMOVE_ENTITY.format(**kwargs),
self.async_schedule_update_ha_state) self.async_remove)
) )
self._remove_callbacks.append( self._remove_callbacks.append(

View File

@ -91,6 +91,8 @@ class EsphomeFan(EsphomeEntity, FanEntity):
"""Return the current speed.""" """Return the current speed."""
if self._state is None: if self._state is None:
return None return None
if not self._static_info.supports_speed:
return None
return FAN_SPEED_INT_TO_STR[self._state.speed] return FAN_SPEED_INT_TO_STR[self._state.speed]
@property @property
@ -98,11 +100,15 @@ class EsphomeFan(EsphomeEntity, FanEntity):
"""Return the oscillation state.""" """Return the oscillation state."""
if self._state is None: if self._state is None:
return None return None
if not self._static_info.supports_oscillation:
return None
return self._state.oscillating return self._state.oscillating
@property @property
def speed_list(self) -> List[str]: def speed_list(self) -> Optional[List[str]]:
"""Get the list of available speeds.""" """Get the list of available speeds."""
if not self._static_info.supports_speed:
return None
return [SPEED_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH] return [SPEED_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH]
@property @property