Add Melissa (HVAC/climate) component (#11503)
* Adding component melissa * Adding sensor component melissa * Adding Melissa climate component * Testing component * Tests for Climate component * Testing Melissa sensor * Fixing review Thank you @rytilahti
This commit is contained in:
1 parent
c204a7c787
commit
f7c9787418
10 files changed
+873
No files matched your search
@@ -0,0 +1,98 @@
|
||||
"""
|
||||
Support for Melissa climate Sensors.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.melissa/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.melissa import DOMAIN, DATA_MELISSA
|
||||
from homeassistant.const import TEMP_CELSIUS, STATE_UNKNOWN
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
DEPENDENCIES = [DOMAIN]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the melissa sensor platform."""
|
||||
sensors = []
|
||||
api = hass.data[DATA_MELISSA]
|
||||
devices = api.fetch_devices().values()
|
||||
|
||||
for device in devices:
|
||||
sensors.append(MelissaTemperatureSensor(device, api))
|
||||
sensors.append(MelissaHumiditySensor(device, api))
|
||||
add_devices(sensors)
|
||||
|
||||
|
||||
class MelissaSensor(Entity):
|
||||
"""Representation of a Melissa Sensor."""
|
||||
|
||||
_type = 'generic'
|
||||
|
||||
def __init__(self, device, api):
|
||||
"""Initialize the sensor."""
|
||||
self._api = api
|
||||
self._state = STATE_UNKNOWN
|
||||
self._name = '{0} {1}'.format(
|
||||
device['name'],
|
||||
self._type
|
||||
)
|
||||
self._serial = device['serial_number']
|
||||
self._data = device['controller_log']
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
def update(self):
|
||||
"""Fetch status from melissa."""
|
||||
self._data = self._api.status(cached=True)
|
||||
|
||||
|
||||
class MelissaTemperatureSensor(MelissaSensor):
|
||||
"""Representation of a Melissa temperature Sensor."""
|
||||
|
||||
_type = 'temperature'
|
||||
_unit = TEMP_CELSIUS
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit
|
||||
|
||||
def update(self):
|
||||
"""Fetch new state data for the sensor."""
|
||||
super().update()
|
||||
try:
|
||||
self._state = self._data[self._serial]['temp']
|
||||
except KeyError:
|
||||
_LOGGER.warning("Unable to get temperature for %s", self.entity_id)
|
||||
|
||||
|
||||
class MelissaHumiditySensor(MelissaSensor):
|
||||
"""Representation of a Melissa humidity Sensor."""
|
||||
|
||||
_type = 'humidity'
|
||||
_unit = '%'
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit
|
||||
|
||||
def update(self):
|
||||
"""Fetch new state data for the sensor."""
|
||||
super().update()
|
||||
try:
|
||||
self._state = self._data[self._serial]['humidity']
|
||||
except KeyError:
|
||||
_LOGGER.warning("Unable to get humidity for %s", self.entity_id)
|
||||
Reference in new issue
Block a user