hass-core/homeassistant/components/zwave_me/sensor.py
Poltorak Serguei 3c5a667d97
Add Z-Wave.Me integration (#65473)
* Add support of Z-Wave.Me Z-Way and RaZberry server (#61182)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: LawfulChaos <kerbalspacema@gmail.com>

* Add switch platform to Z-Wave.Me integration (#64957)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Dmitry Vlasov <kerbalspacema@gmail.com>

* Add button platform to Z-Wave.Me integration (#65109)

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: Dmitry Vlasov <kerbalspacema@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Fix button controller access (#65117)

* Add lock platform to Z-Wave.Me integration #65109 (#65114)

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: Dmitry Vlasov <kerbalspacema@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Add sensor platform to Z-Wave.Me integration (#65132)

* Sensor Entity

* Sensor fixes

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Inline descriotion according to review proposal

* State Classes for sensor

* Generic sensor

* Generic sensor

Co-authored-by: Dmitry Vlasov <kerbalspacema@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Add binary sensor platform to Z-Wave.Me integration (#65306)

* Binary Sensor Entity

* Update docstring

Co-authored-by: Dmitry Vlasov <kerbalspacema@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Add Light Entity platform to Z-Wave.Me integration (#65331)

* Light Entity

* mypy fix

* Fixes, ZWaveMePlatforms enum

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Fixes

* Fixes

* Fixes

Co-authored-by: Dmitry Vlasov <kerbalspacema@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Add Thermostat platform to Z-Wave.Me integration #65331 (#65371)

* Climate entity

* Climate entity

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Climate entity fix

* Clean up

* cleanup

* Import order fix

* Correct naming

Co-authored-by: Dmitry Vlasov <kerbalspacema@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Correct zwave_me .coveragerc (#65491)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: LawfulChaos <kerbalspacema@gmail.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2022-02-07 16:27:11 +01:00

120 lines
3.8 KiB
Python

"""Representation of a sensorMultilevel."""
from __future__ import annotations
from zwave_me_ws import ZWaveMeData
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR,
LIGHT_LUX,
POWER_WATT,
SIGNAL_STRENGTH_DECIBELS,
TEMP_CELSIUS,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ZWaveMeController, ZWaveMeEntity
from .const import DOMAIN, ZWaveMePlatform
SENSORS_MAP: dict[str, SensorEntityDescription] = {
"meterElectric_watt": SensorEntityDescription(
key="meterElectric_watt",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT,
state_class=SensorStateClass.MEASUREMENT,
),
"meterElectric_kilowatt_hour": SensorEntityDescription(
key="meterElectric_kilowatt_hour",
device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
state_class=SensorStateClass.TOTAL_INCREASING,
),
"meterElectric_voltage": SensorEntityDescription(
key="meterElectric_voltage",
device_class=SensorDeviceClass.VOLTAGE,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
state_class=SensorStateClass.MEASUREMENT,
),
"light": SensorEntityDescription(
key="light",
device_class=SensorDeviceClass.ILLUMINANCE,
native_unit_of_measurement=LIGHT_LUX,
state_class=SensorStateClass.MEASUREMENT,
),
"noise": SensorEntityDescription(
key="noise",
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
state_class=SensorStateClass.MEASUREMENT,
),
"currentTemperature": SensorEntityDescription(
key="currentTemperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=TEMP_CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
),
"temperature": SensorEntityDescription(
key="temperature",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=TEMP_CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
),
"generic": SensorEntityDescription(
key="generic",
),
}
DEVICE_NAME = ZWaveMePlatform.SENSOR
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the sensor platform."""
@callback
def add_new_device(new_device: ZWaveMeData) -> None:
controller: ZWaveMeController = hass.data[DOMAIN][config_entry.entry_id]
description = SENSORS_MAP.get(new_device.probeType, SENSORS_MAP["generic"])
sensor = ZWaveMeSensor(controller, new_device, description)
async_add_entities(
[
sensor,
]
)
config_entry.async_on_unload(
async_dispatcher_connect(
hass, f"ZWAVE_ME_NEW_{DEVICE_NAME.upper()}", add_new_device
)
)
class ZWaveMeSensor(ZWaveMeEntity, SensorEntity):
"""Representation of a ZWaveMe sensor."""
def __init__(
self,
controller: ZWaveMeController,
device: ZWaveMeData,
description: SensorEntityDescription,
) -> None:
"""Initialize the device."""
super().__init__(controller=controller, device=device)
self.entity_description = description
@property
def native_value(self) -> str:
"""Return the state of the sensor."""
return self.device.level