Skip to content

Commit

Permalink
Merge pull request #13 from astrandb/NewEntityNaming
Browse files Browse the repository at this point in the history
Update entity naming style
  • Loading branch information
astrandb authored Oct 6, 2022
2 parents bdb5401 + 0199edc commit 13c37e8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
36 changes: 25 additions & 11 deletions custom_components/weatherlink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, PRESSURE_MBAR, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import (
LENGTH_MILLIMETERS,
PERCENTAGE,
PRECIPITATION_MILLIMETERS_PER_HOUR,
PRESSURE_MBAR,
SPEED_METERS_PER_SECOND,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -38,15 +46,15 @@ class WLSensorDescription(SensorEntityDescription):
key="OutsideTemp",
tag="temp_c",
device_class=SensorDeviceClass.TEMPERATURE,
name="Outside Temperature",
name="Outside temperature",
native_unit_of_measurement=TEMP_CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
),
WLSensorDescription(
key="OutsideHumidity",
tag="relative_humidity",
device_class=SensorDeviceClass.HUMIDITY,
name="Outside Humidity",
name="Outside humidity",
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
Expand All @@ -55,7 +63,7 @@ class WLSensorDescription(SensorEntityDescription):
tag="relative_humidity_in",
subtag=SUBTAG_1,
device_class=SensorDeviceClass.HUMIDITY,
name="Inside Humidity",
name="Inside humidity",
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
),
Expand All @@ -71,10 +79,11 @@ class WLSensorDescription(SensorEntityDescription):
WLSensorDescription(
key="Wind",
tag="wind_mph",
device_class=SensorDeviceClass.SPEED,
icon="mdi:weather-windy",
name="Wind",
convert=lambda x: x * 1609 / 3600,
native_unit_of_measurement="m/s",
native_unit_of_measurement=SPEED_METERS_PER_SECOND,
state_class=SensorStateClass.MEASUREMENT,
),
WLSensorDescription(
Expand All @@ -88,7 +97,7 @@ class WLSensorDescription(SensorEntityDescription):
tag="temp_in_f",
subtag=SUBTAG_1,
device_class=SensorDeviceClass.TEMPERATURE,
name="Inside Temperature",
name="Inside temperature",
native_unit_of_measurement=TEMP_FAHRENHEIT,
state_class=SensorStateClass.MEASUREMENT,
),
Expand All @@ -97,8 +106,9 @@ class WLSensorDescription(SensorEntityDescription):
tag="rain_day_in",
subtag=SUBTAG_1,
icon="mdi:weather-pouring",
name="Rain Today",
native_unit_of_measurement="mm",
name="Rain today",
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=LENGTH_MILLIMETERS,
convert=lambda x: x * 25.4,
state_class=SensorStateClass.MEASUREMENT,
),
Expand All @@ -108,7 +118,8 @@ class WLSensorDescription(SensorEntityDescription):
subtag=SUBTAG_1,
icon="mdi:weather-pouring",
name="Rain rate",
native_unit_of_measurement="mm/h",
device_class=SensorDeviceClass.SPEED,
native_unit_of_measurement=PRECIPITATION_MILLIMETERS_PER_HOUR,
convert=lambda x: x * 25.4,
state_class=SensorStateClass.MEASUREMENT,
),
Expand All @@ -118,7 +129,8 @@ class WLSensorDescription(SensorEntityDescription):
subtag=SUBTAG_1,
icon="mdi:weather-pouring",
name="Rain this month",
native_unit_of_measurement="mm",
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=LENGTH_MILLIMETERS,
convert=lambda x: x * 25.4,
state_class=SensorStateClass.MEASUREMENT,
),
Expand All @@ -128,7 +140,8 @@ class WLSensorDescription(SensorEntityDescription):
subtag=SUBTAG_1,
icon="mdi:weather-pouring",
name="Rain this year",
native_unit_of_measurement="mm",
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=LENGTH_MILLIMETERS,
convert=lambda x: x * 25.4,
state_class=SensorStateClass.TOTAL_INCREASING,
),
Expand Down Expand Up @@ -165,6 +178,7 @@ def __init__(self, coordinator, description: WLSensorDescription):
"""Initialize the sensor."""
super().__init__(coordinator)
self.entity_description = description
self._attr_has_entity_name = True
self._attr_unique_id = (
f"{self.coordinator.data[SUBTAG_1]['DID']}-{self.entity_description.key}"
)
Expand Down
4 changes: 2 additions & 2 deletions hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"domains": [
"sensor"
],
"homeassistant": "2021.12.0b0",
"homeassistant": "2022.10.0",
"iot_class": [
"Cloud Poll"
],
"zip_release": true,
"filename": "weatherlink.zip",
"render_readme": true
}
}

0 comments on commit 13c37e8

Please sign in to comment.