Skip to content

Commit

Permalink
Add aircleaner and humidify service to nexia climate (home-assistant#…
Browse files Browse the repository at this point in the history
…33078)

* Add aircleaner and humidify service to nexia climate

* These were removed from the original merge to reduce review scope

* Additional tests for binary_sensor, sensor, and climate states

* Switch to signals for services

Get rid of everywhere we call device and change to zone or thermostat
as it was too confusing

Renames to make it clear that zone and thermostat are tightly coupled

* Make scene activation responsive

* no need to use update for only one key/value

* stray comma

* use async_call_later

* its async, need ()s

* cleaner

* merge entity platform services testing branch
  • Loading branch information
bdraco authored Mar 23, 2020
1 parent 0e3dc79 commit b8fdebd
Show file tree
Hide file tree
Showing 13 changed files with 576 additions and 292 deletions.
5 changes: 2 additions & 3 deletions homeassistant/components/nexia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import DATA_NEXIA, DOMAIN, NEXIA_DEVICE, PLATFORMS, UPDATE_COORDINATOR
from .const import DOMAIN, NEXIA_DEVICE, PLATFORMS, UPDATE_COORDINATOR

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -94,8 +94,7 @@ async def _async_update_data():
update_interval=timedelta(seconds=DEFAULT_UPDATE_RATE),
)

hass.data[DOMAIN][entry.entry_id] = {}
hass.data[DOMAIN][entry.entry_id][DATA_NEXIA] = {
hass.data[DOMAIN][entry.entry_id] = {
NEXIA_DEVICE: nexia_home,
UPDATE_COORDINATOR: coordinator,
}
Expand Down
59 changes: 12 additions & 47 deletions homeassistant/components/nexia/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
"""Support for Nexia / Trane XL Thermostats."""

from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.const import ATTR_ATTRIBUTION

from .const import (
ATTRIBUTION,
DATA_NEXIA,
DOMAIN,
MANUFACTURER,
NEXIA_DEVICE,
UPDATE_COORDINATOR,
)
from .entity import NexiaEntity
from .const import DOMAIN, NEXIA_DEVICE, UPDATE_COORDINATOR
from .entity import NexiaThermostatEntity


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up sensors for a Nexia device."""

nexia_data = hass.data[DOMAIN][config_entry.entry_id][DATA_NEXIA]
nexia_data = hass.data[DOMAIN][config_entry.entry_id]
nexia_home = nexia_data[NEXIA_DEVICE]
coordinator = nexia_data[UPDATE_COORDINATOR]

Expand All @@ -42,48 +34,21 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(entities, True)


class NexiaBinarySensor(NexiaEntity, BinarySensorDevice):
class NexiaBinarySensor(NexiaThermostatEntity, BinarySensorDevice):
"""Provices Nexia BinarySensor support."""

def __init__(self, coordinator, device, sensor_call, sensor_name):
def __init__(self, coordinator, thermostat, sensor_call, sensor_name):
"""Initialize the nexia sensor."""
super().__init__(coordinator)
self._coordinator = coordinator
self._device = device
self._name = f"{self._device.get_name()} {sensor_name}"
super().__init__(
coordinator,
thermostat,
name=f"{thermostat.get_name()} {sensor_name}",
unique_id=f"{thermostat.thermostat_id}_{sensor_call}",
)
self._call = sensor_call
self._unique_id = f"{self._device.thermostat_id}_{sensor_call}"
self._state = None

@property
def unique_id(self):
"""Return the unique id of the binary sensor."""
return self._unique_id

@property
def name(self):
"""Return the name of the sensor."""
return self._name

@property
def device_info(self):
"""Return the device_info of the device."""
return {
"identifiers": {(DOMAIN, self._device.thermostat_id)},
"name": self._device.get_name(),
"model": self._device.get_model(),
"sw_version": self._device.get_firmware(),
"manufacturer": MANUFACTURER,
}

@property
def device_state_attributes(self):
"""Return the device specific state attributes."""
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
}

@property
def is_on(self):
"""Return the status of the sensor."""
return getattr(self._device, self._call)()
return getattr(self._thermostat, self._call)()
Loading

0 comments on commit b8fdebd

Please sign in to comment.