mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add support for Shelly Gas to the Shelly integration (#39478)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
6d1ba10788
commit
7e50a4999c
@ -2,6 +2,7 @@
|
||||
import aioshelly
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_GAS,
|
||||
DEVICE_CLASS_MOISTURE,
|
||||
DEVICE_CLASS_OPENING,
|
||||
DEVICE_CLASS_SMOKE,
|
||||
@ -15,6 +16,7 @@ from .const import DOMAIN
|
||||
SENSORS = {
|
||||
"dwIsOpened": DEVICE_CLASS_OPENING,
|
||||
"flood": DEVICE_CLASS_MOISTURE,
|
||||
"gas": DEVICE_CLASS_GAS,
|
||||
"overpower": None,
|
||||
"overtemp": None,
|
||||
"smoke": DEVICE_CLASS_SMOKE,
|
||||
@ -66,10 +68,30 @@ class ShellySensor(ShellyBlockEntity, BinarySensorEntity):
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if sensor state is 1."""
|
||||
"""Return true if sensor state is on."""
|
||||
if self.attribute == "gas":
|
||||
# Gas sensor value of Shelly Gas can be none/mild/heavy/test. We return True
|
||||
# when the value is mild or heavy.
|
||||
return getattr(self.block, self.attribute) in ["mild", "heavy"]
|
||||
return bool(getattr(self.block, self.attribute))
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Device class of sensor."""
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
if self.attribute == "gas":
|
||||
# We return raw value of the gas sensor as an attribute.
|
||||
return {"detected": getattr(self.block, self.attribute)}
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Available."""
|
||||
if self.attribute == "gas":
|
||||
# "sensorOp" is "normal" when Shelly Gas is working properly and taking
|
||||
# measurements.
|
||||
return super().available and self.block.sensorOp == "normal"
|
||||
return super().available
|
||||
|
@ -3,6 +3,7 @@ import aioshelly
|
||||
|
||||
from homeassistant.components import sensor
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
ELECTRICAL_CURRENT_AMPERE,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
POWER_WATT,
|
||||
@ -18,6 +19,7 @@ from .const import DOMAIN
|
||||
|
||||
SENSORS = {
|
||||
"battery": [UNIT_PERCENTAGE, sensor.DEVICE_CLASS_BATTERY],
|
||||
"concentration": [CONCENTRATION_PARTS_PER_MILLION, None],
|
||||
"current": [ELECTRICAL_CURRENT_AMPERE, sensor.DEVICE_CLASS_CURRENT],
|
||||
"deviceTemp": [None, sensor.DEVICE_CLASS_TEMPERATURE],
|
||||
"energy": [ENERGY_KILO_WATT_HOUR, sensor.DEVICE_CLASS_ENERGY],
|
||||
@ -117,3 +119,12 @@ class ShellySensor(ShellyBlockEntity, Entity):
|
||||
def device_class(self):
|
||||
"""Device class of sensor."""
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Available."""
|
||||
if self.attribute == "concentration":
|
||||
# "sensorOp" is "normal" when the Shelly Gas is working properly and taking
|
||||
# measurements.
|
||||
return super().available and self.block.sensorOp == "normal"
|
||||
return super().available
|
||||
|
Loading…
x
Reference in New Issue
Block a user