Skip to content

Commit

Permalink
add state classes to Sensors
Browse files Browse the repository at this point in the history
change version from 0.1.9 to 0.1.10
add @diefraschw to codeowners
  • Loading branch information
diefraschw committed Apr 2, 2023
1 parent c2ecb78 commit ddc91a8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 11 deletions.
4 changes: 2 additions & 2 deletions custom_components/ws980wifi/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"name": "ELV WS980WiFi ",
"documentation": "https://github.com/patschbo/ws980wifi/",
"dependencies": [],
"codeowners": ["@eXtgmA", "@patschbo"],
"codeowners": ["@eXtgmA", "@patschbo", "@diefraschw"],
"requirements": [],
"version": "0.1.9",
"version": "0.1.10",
"integration_type": "hub"
}
71 changes: 62 additions & 9 deletions custom_components/ws980wifi/sensor.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"""Platform for sensor integration."""
# diefraschw 04/2023:
# change deprecated TEMP_CELSIUS to UnitOfTemperature.CELSIUS
# change deprecated SPEED_METERS_PER_SECOND to
# change deprecated LENGTH_MILLIMITERS to
# change deprecated SPEED_METERS_PER_SECOND to UnitOfSpeed.METERS_PER_SECOND
# change deprecated LENGTH_MILLIMITERS to UnitOfLength.MILLIMETERS
# change unit of rain to mm/h
# remove unused import of WIND_SPEED
# add unique_id
# add unique_id (makes the sensors configurable via the HA GUI)
# derive class WeatherSensor from SensorEntity instead of Entity
# set _attr_native_unit_of_measurement instead of _unit_of_measurement
# update native_value instead of state
# add dew_point to regular expression for values which can become negative
# add dew_point to regular expression for values which can become negative (temperature)
# define SensorDeviceClass for all measurements where SensorDeviceClass is available
# change direct access to class attributes to access via property
# add state classes to Sensors

import logging
import select
Expand All @@ -27,6 +28,7 @@
PLATFORM_SCHEMA,
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)

from homeassistant.const import (
Expand Down Expand Up @@ -56,7 +58,7 @@
from homeassistant.core import HomeAssistant

# __version__ = '0.1.9'
__version__ = "0.1.9 diefraschw"
__version__ = "0.1.10"

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -126,13 +128,15 @@
}"""

SENSOR_PROPERTIES = {
# 0=sensor name, 1=native unit, 2=SensorDeviceClass, 3=hex-Index, 4=hex length of value, 5=factor to divide value by, 6= state class
"inside_temperature": [
"inside temperature",
TEMP_CELSIUS,
SensorDeviceClass.TEMPERATURE,
"7",
"2",
"10",
SensorStateClass.MEASUREMENT,
],
"outside_temperature": [
"outside temperature",
Expand All @@ -141,6 +145,7 @@
"10",
"2",
"10",
SensorStateClass.MEASUREMENT,
],
"dew_point": [
"dew point",
Expand All @@ -149,6 +154,7 @@
"13",
"2",
"10",
SensorStateClass.MEASUREMENT,
],
"apparent_temperature": [
"apparent temperature",
Expand All @@ -157,6 +163,7 @@
"16",
"2",
"10",
SensorStateClass.MEASUREMENT,
],
"heat_index": [
"heat index",
Expand All @@ -165,6 +172,7 @@
"19",
"2",
"10",
SensorStateClass.MEASUREMENT,
],
"inside_humidity": [
"inside humidity",
Expand All @@ -173,6 +181,7 @@
"22",
"1",
"1",
SensorStateClass.MEASUREMENT,
],
"outside_humidity": [
"outside humidity",
Expand All @@ -181,6 +190,7 @@
"24",
"1",
"1",
SensorStateClass.MEASUREMENT,
],
"pressure_absolute": [
"pressure absolute",
Expand All @@ -189,6 +199,7 @@
"26",
"2",
"10",
SensorStateClass.MEASUREMENT,
],
"pressure_relative": [
"pressure relative",
Expand All @@ -197,15 +208,25 @@
"29",
"2",
"10",
SensorStateClass.MEASUREMENT,
],
"wind_direction": [
"wind direction",
DEGREE,
None,
"32",
"2",
"1",
SensorStateClass.MEASUREMENT,
],
"wind_direction": ["wind direction", DEGREE, None, "32", "2", "1"],
"wind_speed": [
"wind speed",
SPEED_METERS_PER_SECOND,
SensorDeviceClass.WIND_SPEED,
"35",
"2",
"10",
SensorStateClass.MEASUREMENT,
],
"gust": [
"gust",
Expand All @@ -214,6 +235,7 @@
"38",
"2",
"10",
SensorStateClass.MEASUREMENT,
],
"rain": [
"rain",
Expand All @@ -222,6 +244,7 @@
"41",
"4",
"10",
SensorStateClass.MEASUREMENT,
],
"rain_day": [
"rain day",
Expand All @@ -230,6 +253,7 @@
"46",
"4",
"10",
SensorStateClass.TOTAL_INCREASING,
],
"rain_week": [
"rain week",
Expand All @@ -238,6 +262,7 @@
"51",
"4",
"10",
SensorStateClass.TOTAL_INCREASING,
],
"rain_month": [
"rain month",
Expand All @@ -246,6 +271,7 @@
"56",
"4",
"10",
SensorStateClass.TOTAL_INCREASING,
],
"rain_year": [
"rain year",
Expand All @@ -254,6 +280,7 @@
"61",
"4",
"10",
SensorStateClass.TOTAL_INCREASING,
],
"rain_total": [
"rain total",
Expand All @@ -262,10 +289,35 @@
"66",
"4",
"10",
SensorStateClass.TOTAL_INCREASING,
],
"light": [
"light",
LIGHT_LUX,
SensorDeviceClass.ILLUMINANCE,
"71",
"4",
"10",
SensorStateClass.MEASUREMENT,
],
"uv_value": [
"uv value",
UV_VALUE,
None,
"76",
"2",
"10",
SensorStateClass.MEASUREMENT,
],
"uv_index": [
"uv index",
UV_INDEX,
None,
"79",
"1",
"1",
SensorStateClass.MEASUREMENT,
],
"light": ["light", LIGHT_LUX, SensorDeviceClass.ILLUMINANCE, "71", "4", "10"],
"uv_value": ["uv value", UV_VALUE, None, "76", "2", "10"],
"uv_index": ["uv index", UV_INDEX, None, "79", "1", "1"],
}

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
Expand Down Expand Up @@ -322,6 +374,7 @@ def __init__(self, name, sensor_property, u_id) -> None:
self._hexIndex = int(SENSOR_PROPERTIES[self.type][3])
self._hexLength = int(SENSOR_PROPERTIES[self.type][4])
self._decimalPlace = int(SENSOR_PROPERTIES[self.type][5])
self._attr_state_class = SENSOR_PROPERTIES[self.type][6]
self._unique_id = u_id + "-" + self.type

@property
Expand Down

0 comments on commit ddc91a8

Please sign in to comment.