XS1 component (#19115)

* added xs1 main component
added implementations for switch, sensor, climate and binary_sensor

* updated code
fixed styling
added comments
removed binary_sensor (wasn't working)

* ran "gen_requirements_all.py" script

* fixed linting issues

* added config options for port and ssl
small fixes

* use already defined config constants instead of defining new ones

* avoid passing in hass to the entity

* use async keyword and proper asyncio calls
limit updates with a global lock to prevent overwhelming the gateway with concurrent requests
change info logger calls to debug

* update dependency

* removed unneeded constant

* fix lint issues

* updated requirements

* removed unused imports

* fixed some flake8 errors

* fixed some flake8 errors

* changed imports to absolute paths

* fixed some lint errors

* fixed some lint errors

* fix update of attached sensor

* reordered imports
added config defaults
check if platform is available
changed docstring

* lint fix

* review fixes

* isort

* import fix

* review fix

* review fix

* review fix

* removed unused imports

* lint fix

* lint fix

* climate fix
exclude sensors that will be used in climate component from default sensor category

* .coveragerc fix

* lint fix

* moved platform to it's own package
This commit is contained in:
Markus Ressel authored and Martin Hjelmare committed 2019-02-07 23:21:41 +01:00
1 parent a9672b0d52
commit 542f024356
6 files changed
+341

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
"""
Support for XS1 sensors.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.xs1/
"""
import logging
from homeassistant.components.xs1 import (
ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS, XS1DeviceEntity)
from homeassistant.helpers.entity import Entity
DEPENDENCIES = ['xs1']
_LOGGER = logging.getLogger(__name__)
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the XS1 sensor platform."""
from xs1_api_client.api_constants import ActuatorType
sensors = hass.data[COMPONENT_DOMAIN][SENSORS]
actuators = hass.data[COMPONENT_DOMAIN][ACTUATORS]
sensor_entities = []
for sensor in sensors:
belongs_to_climate_actuator = False
for actuator in actuators:
if actuator.type() == ActuatorType.TEMPERATURE and \
actuator.name() in sensor.name():
belongs_to_climate_actuator = True
break
if not belongs_to_climate_actuator:
sensor_entities.append(XS1Sensor(sensor))
async_add_entities(sensor_entities)
class XS1Sensor(XS1DeviceEntity, Entity):
"""Representation of a Sensor."""
@property
def name(self):
"""Return the name of the sensor."""
return self.device.name()
@property
def state(self):
"""Return the state of the sensor."""
return self.device.value()
@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return self.device.unit()