Skip to content

Commit

Permalink
chore: remove references to imperial units (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw authored Dec 28, 2024
1 parent 953c0d1 commit 30eb29b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ config/*
!config/configuration.yaml

# Integration specific files
.access-token
.access-token
tests
35 changes: 0 additions & 35 deletions custom_components/cloudweatherproxy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,27 @@
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
),
UnitOfPressure.INHG: SensorEntityDescription(
key="PRESSURE_INHG",
device_class=SensorDeviceClass.PRESSURE,
native_unit_of_measurement=UnitOfPressure.INHG,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
),
UnitOfTemperature.CELSIUS: SensorEntityDescription(
key="TEMPERATURE_C",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
),
UnitOfTemperature.FAHRENHEIT: SensorEntityDescription(
key="TEMPERATURE_F",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
),
UnitOfPrecipitationDepth.MILLIMETERS: SensorEntityDescription(
key="RAIN_MM",
device_class=SensorDeviceClass.PRECIPITATION,
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
state_class=SensorStateClass.TOTAL_INCREASING,
suggested_display_precision=2,
),
UnitOfPrecipitationDepth.INCHES: SensorEntityDescription(
key="RAIN_IN",
device_class=SensorDeviceClass.PRECIPITATION,
native_unit_of_measurement=UnitOfPrecipitationDepth.INCHES,
state_class=SensorStateClass.TOTAL_INCREASING,
suggested_display_precision=2,
),
UnitOfSpeed.METERS_PER_SECOND: SensorEntityDescription(
key="WIND_SPEED_MS",
device_class=SensorDeviceClass.WIND_SPEED,
native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
),
UnitOfSpeed.MILES_PER_HOUR: SensorEntityDescription(
key="WIND_SPEED_MPH",
device_class=SensorDeviceClass.WIND_SPEED,
native_unit_of_measurement=UnitOfSpeed.MILES_PER_HOUR,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
),
UnitOfIrradiance.WATTS_PER_SQUARE_METER: SensorEntityDescription(
key="SOLAR_RADIATION_W_M2",
device_class=SensorDeviceClass.IRRADIANCE,
Expand All @@ -100,13 +72,6 @@
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
),
UnitOfVolumetricFlux.INCHES_PER_HOUR: SensorEntityDescription(
key="RAIN_RATE_IN",
device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
native_unit_of_measurement=UnitOfVolumetricFlux.INCHES_PER_HOUR,
state_class=SensorStateClass.MEASUREMENT,
suggested_display_precision=2,
),
DEGREE: SensorEntityDescription(
key="WIND_DIRECTION",
native_unit_of_measurement=DEGREE,
Expand Down
12 changes: 2 additions & 10 deletions custom_components/cloudweatherproxy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM, UnitSystem

from .const import DOMAIN, UNIT_DESCRIPTION_MAPPING

Expand Down Expand Up @@ -96,25 +95,18 @@ def __init__(
self,
sensor: Sensor,
station: WeatherStation,
unit_system: UnitSystem,
name: str,
) -> None:
"""Initialize the sensor entity."""
super().__init__(sensor, station)
self.unit_system = unit_system
self._name = name
if unit_system is US_CUSTOMARY_SYSTEM:
description = UNIT_DESCRIPTION_MAPPING[sensor.imperial_unit]
else:
description = UNIT_DESCRIPTION_MAPPING[sensor.metric_unit]
description = UNIT_DESCRIPTION_MAPPING[sensor.unit]
self.entity_description = description

@property
def native_value(self) -> StateType | None:
"""Return the state of the entity."""
if self.unit_system is US_CUSTOMARY_SYSTEM:
return self.sensor.imperial
return self.sensor.metric
return self.sensor.value

@property
def name(self) -> str:
Expand Down

0 comments on commit 30eb29b

Please sign in to comment.