Skip to content

Commit

Permalink
fix: new HA units (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotak authored Dec 29, 2024
1 parent 041a939 commit d4e2839
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 75 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Configuration variables:
- **uv_index**: UV Index
- **apparent_temp**: Apparent temperature (°C or °F)
- **apparent_temp_min**: Min pparent temperature (°C or °F)
- **apparent_temp_maz**: Max pparent temperature (°C or °F)
- **apparent_temp_max**: Max pparent temperature (°C or °F)
## Install via [HACS](https://github.com/custom-components/hacs)
You can find this integration in a store.
Expand Down
2 changes: 1 addition & 1 deletion custom_components/clientraw/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/pilotak/homeassistant-clientraw/issues",
"requirements": [],
"version": "2.7.0"
"version": "2.7.1"
}
277 changes: 206 additions & 71 deletions custom_components/clientraw/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
PLATFORM_SCHEMA,
DOMAIN as SENSOR_DOMAIN)
from homeassistant.const import (
CONF_MONITORED_CONDITIONS, TEMP_CELSIUS, TEMP_FAHRENHEIT, PRESSURE_HPA,
PRESSURE_INHG, LENGTH_METERS, LENGTH_FEET, LENGTH_INCHES, STATE_UNKNOWN,
STATE_UNAVAILABLE, UV_INDEX, UnitOfIrradiance)
CONF_MONITORED_CONDITIONS, DEGREE, PERCENTAGE, STATE_UNKNOWN,
STATE_UNAVAILABLE, UV_INDEX, UnitOfIrradiance, UnitOfLength,
UnitOfPressure, UnitOfSpeed, UnitOfTemperature)
from homeassistant.util import slugify
from homeassistant.util.unit_conversion import (
TemperatureConverter, PressureConverter, DistanceConverter)
Expand All @@ -24,68 +24,189 @@
async_call_later)
from homeassistant.util.unit_system import METRIC_SYSTEM

__version__ = '2.7.0'
__version__ = '2.7.1'

_LOGGER = logging.getLogger(__name__)

CONF_ATTRIBUTION = "Weather forecast delivered by your WD Clientraw enabled " \
"weather station."

SENSOR_TYPES = {
'dewpoint': ['Dewpoint', TEMP_CELSIUS, TEMP_FAHRENHEIT, 'mdi:weather-fog'],
'heat_index': ['Heat index', TEMP_CELSIUS, TEMP_FAHRENHEIT,
'mdi:thermometer'],
'temp': ['Temperature', TEMP_CELSIUS, TEMP_FAHRENHEIT, 'mdi:thermometer'],
'temp_indoor': ['Indoor Temperature', TEMP_CELSIUS, TEMP_FAHRENHEIT,
'mdi:thermometer'],
'temp_day_max': ['Today MAX temperature', TEMP_CELSIUS, TEMP_FAHRENHEIT,
'mdi:thermometer'],
'temp_day_min': ['Today MIN temperature', TEMP_CELSIUS, TEMP_FAHRENHEIT,
'mdi:thermometer'],
'humidex': ['Humidex', TEMP_CELSIUS, TEMP_FAHRENHEIT, 'mdi:thermometer'],
'wind_degrees': ['Wind Degrees', '°', '°', 'mdi:subdirectory-arrow-right'],
'wind_dir': ['Wind Direction', None, None, 'mdi:subdirectory-arrow-right'],
'wind_gust_hour': ['Wind Gust last hour', 'km/h', 'mph',
'mdi:weather-windy'],
'wind_gust_day': ['Wind Gust last day', 'km/h', 'mph',
'mdi:weather-windy'],
'wind_speed': ['Wind Speed', 'km/h', 'mph', 'mdi:weather-windy-variant'],
'wind_speed_average': ['60s Avg Wind Speed', 'km/h', 'mph',
'mdi:weather-windy-variant'],
'wind_speed_avg_10min': ['10 Min Avg Wind Speed', 'km/h', 'mph',
'mdi:weather-windy-variant'],
'symbol': ['Symbol', None, None, 'mdi:triangle-outline'],
'daily_rain': ['Daily Rain', 'mm', LENGTH_INCHES, 'mdi:weather-rainy'],
'yesterday_rain': ['Yesterday Rain', 'mm', LENGTH_INCHES,
'mdi:weather-rainy'],
'monthly_rain': ['Monthly Rain', 'mm', LENGTH_INCHES,
'mdi:weather-rainy'],
'yearly_rain': ['Yearly Rain', 'mm', LENGTH_INCHES, 'mdi:weather-rainy'],
'rain_rate': ['Rain Rate', 'mm', LENGTH_INCHES, 'mdi:weather-rainy'],
'pressure': ['Pressure', PRESSURE_HPA, PRESSURE_INHG, 'mdi:trending-up'],
'humidity': ['Humidity', '%', '%', 'mdi:water-percent'],
'humidity_indoor': ['Indoor Humidity', '%', '%', 'mdi:water-percent'],
'cloud_height': ['Cloud Height', LENGTH_METERS, LENGTH_FEET,
'mdi:cloud-outline'],
'forecast': ['Forecast', None, None, "mdi:card-text-outline"],
'station': ['Station', None, None, "mdi:home-thermometer-outline"],
'date': ['Date', None, None, "mdi:calendar"],
'wind_chill': ['Wind Chill', TEMP_CELSIUS, TEMP_FAHRENHEIT,
'mdi:thermometer'],
'wind_chill_max': ['Today MAX Wind Chill', TEMP_CELSIUS, TEMP_FAHRENHEIT,
'mdi:thermometer'],
'wind_chill_min': ['Today MIN Wind Chill', TEMP_CELSIUS, TEMP_FAHRENHEIT,
'mdi:thermometer'],
'vp_solar': ['VP solar', UnitOfIrradiance.WATTS_PER_SQUARE_METER,
UnitOfIrradiance.BTUS_PER_HOUR_SQUARE_FOOT,
'mdi:solar-power'],
'uv_index': ['UV index', UV_INDEX, UV_INDEX, 'mdi:white-balance-sunny'],
'apparent_temp': ['Apparent temperature', TEMP_CELSIUS, TEMP_FAHRENHEIT,
'mdi:thermometer'],
'apparent_temp_min': ['Apparent temperature', TEMP_CELSIUS,
TEMP_FAHRENHEIT, 'mdi:thermometer'],
'apparent_temp_max': ['Apparent temperature', TEMP_CELSIUS,
TEMP_FAHRENHEIT, 'mdi:thermometer']
'dewpoint': [
'Dewpoint',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:weather-fog'],
'heat_index': [
'Heat index',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'temp': [
'Temperature',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'temp_indoor': [
'Indoor Temperature',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'temp_day_max': [
'Today MAX temperature',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'temp_day_min': [
'Today MIN temperature',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'humidex': [
'Humidex',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'wind_degrees': [
'Wind Degrees',
DEGREE,
DEGREE,
'mdi:subdirectory-arrow-right'],
'wind_dir': [
'Wind Direction',
None,
None,
'mdi:subdirectory-arrow-right'],
'wind_gust_hour': [
'Wind Gust last hour',
UnitOfSpeed.KILOMETERS_PER_HOUR,
UnitOfSpeed.MILES_PER_HOUR,
'mdi:weather-windy'],
'wind_gust_day': [
'Wind Gust last day',
UnitOfSpeed.KILOMETERS_PER_HOUR,
UnitOfSpeed.MILES_PER_HOUR,
'mdi:weather-windy'],
'wind_speed': [
'Wind Speed',
UnitOfSpeed.KILOMETERS_PER_HOUR,
UnitOfSpeed.MILES_PER_HOUR,
'mdi:weather-windy-variant'],
'wind_speed_average': [
'60s Avg Wind Speed',
UnitOfSpeed.KILOMETERS_PER_HOUR,
UnitOfSpeed.MILES_PER_HOUR,
'mdi:weather-windy-variant'],
'wind_speed_avg_10min': [
'10 Min Avg Wind Speed',
UnitOfSpeed.KILOMETERS_PER_HOUR,
UnitOfSpeed.MILES_PER_HOUR,
'mdi:weather-windy-variant'],
'symbol': [
'Symbol',
None,
None,
'mdi:triangle-outline'],
'daily_rain': [
'Daily Rain',
UnitOfLength.MILLIMETERS,
UnitOfLength.INCHES,
'mdi:weather-rainy'],
'yesterday_rain': [
'Yesterday Rain',
UnitOfLength.MILLIMETERS,
UnitOfLength.INCHES,
'mdi:weather-rainy'],
'monthly_rain': [
'Monthly Rain',
UnitOfLength.MILLIMETERS,
UnitOfLength.INCHES,
'mdi:weather-rainy'],
'yearly_rain': [
'Yearly Rain',
UnitOfLength.MILLIMETERS,
UnitOfLength.INCHES,
'mdi:weather-rainy'],
'rain_rate': [
'Rain Rate',
UnitOfLength.MILLIMETERS,
UnitOfLength.INCHES,
'mdi:weather-rainy'],
'pressure': [
'Pressure',
UnitOfPressure.HPA,
UnitOfPressure.INHG,
'mdi:trending-up'],
'humidity': [
'Humidity',
PERCENTAGE,
PERCENTAGE,
'mdi:water-percent'],
'humidity_indoor': [
'Indoor Humidity',
PERCENTAGE,
PERCENTAGE,
'mdi:water-percent'],
'cloud_height': [
'Cloud Height',
UnitOfLength.METERS,
UnitOfLength.FEET,
'mdi:cloud-outline'],
'forecast': [
'Forecast',
None,
None,
"mdi:card-text-outline"],
'station': [
'Station',
None,
None,
"mdi:home-thermometer-outline"],
'date': [
'Date',
None,
None,
"mdi:calendar"],
'wind_chill': [
'Wind Chill',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'wind_chill_max': [
'Today MAX Wind Chill',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'wind_chill_min': [
'Today MIN Wind Chill',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'vp_solar': [
'VP solar',
UnitOfIrradiance.WATTS_PER_SQUARE_METER,
UnitOfIrradiance.BTUS_PER_HOUR_SQUARE_FOOT,
'mdi:solar-power'],
'uv_index': [
'UV index',
UV_INDEX,
UV_INDEX,
'mdi:white-balance-sunny'],
'apparent_temp': [
'Apparent temperature',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'apparent_temp_min': [
'Apparent temperature',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer'],
'apparent_temp_max': [
'Apparent temperature',
UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT,
'mdi:thermometer']
}

CONF_URL = 'url'
Expand Down Expand Up @@ -298,7 +419,8 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
temperature = TemperatureConverter.convert(
temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT)
temperature, UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT)

new_state = round(temperature, 2)
else:
Expand All @@ -311,7 +433,8 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
temperature = TemperatureConverter.convert(
temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT)
temperature, UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT)

new_state = round(temperature, 2)
else:
Expand Down Expand Up @@ -393,8 +516,12 @@ def try_again(err: str):
pressure = float(self.data[6])

if self.hass.config.units is not METRIC_SYSTEM:
pressure = round(PressureConverter.convert(
pressure, PRESSURE_HPA, PRESSURE_INHG), 2)
pressure = round(
PressureConverter.convert(
pressure,
UnitOfPressure.HPA,
UnitOfPressure.INHG),
2)

new_state = round(pressure, 2)
else:
Expand Down Expand Up @@ -439,7 +566,7 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
height = DistanceConverter.convert(
height, LENGTH_METERS, LENGTH_FEET)
height, UnitOfLength.METERS, UnitOfLength.FEET)

new_state = round(height, 2)
else:
Expand All @@ -452,7 +579,8 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
temperature = TemperatureConverter.convert(
temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT)
temperature, UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT)

new_state = round(temperature, 2)
else:
Expand All @@ -465,7 +593,8 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
temperature = TemperatureConverter.convert(
temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT)
temperature, UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT)

new_state = round(temperature, 2)
else:
Expand All @@ -478,7 +607,8 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
temperature = TemperatureConverter.convert(
temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT)
temperature, UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT)

new_state = round(temperature, 2)
else:
Expand Down Expand Up @@ -511,7 +641,8 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
temperature = TemperatureConverter.convert(
temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT)
temperature, UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT)

new_state = round(temperature, 2)
else:
Expand All @@ -524,7 +655,8 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
temperature = TemperatureConverter.convert(
temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT)
temperature, UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT)

new_state = round(temperature, 2)
else:
Expand Down Expand Up @@ -553,7 +685,8 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
temperature = TemperatureConverter.convert(
temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT)
temperature, UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT)

new_state = round(temperature, 2)
else:
Expand All @@ -566,7 +699,8 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
temperature = TemperatureConverter.convert(
temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT)
temperature, UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT)

new_state = round(temperature, 2)
else:
Expand All @@ -579,7 +713,8 @@ def try_again(err: str):

if self.hass.config.units is not METRIC_SYSTEM:
temperature = TemperatureConverter.convert(
temperature, TEMP_CELSIUS, TEMP_FAHRENHEIT)
temperature, UnitOfTemperature.CELSIUS,
UnitOfTemperature.FAHRENHEIT)

new_state = round(temperature, 2)
else:
Expand Down
Loading

0 comments on commit d4e2839

Please sign in to comment.