Skip to content

Commit

Permalink
Revert "fix: homeassistant doesn't accept the conversion from lux to …
Browse files Browse the repository at this point in the history
…w/m²"

This reverts commit fedb00e.
  • Loading branch information
lhw committed Jun 1, 2024
1 parent ac0bc61 commit a1f39bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions aiocloudweather/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def in_to_mm(length: float) -> float:
return round(length * 25.4, 2)


@unit(UnitOfIrradiance.WATTS_PER_SQUARE_METER)
def lux_to_wm2(lux: float) -> float:
"""Convert lux to watts per square meter (W/m²)."""
return lux * 0.0079


@unit(UnitOfSpeed.METERS_PER_SECOND)
def mph_to_ms(speed: float) -> float:
"""Convert miles per hour (mph) to meters per second (m/s)."""
Expand All @@ -62,6 +68,13 @@ def mm_to_in(length: float) -> float:
"""Convert millimeters (mm) to inches."""
return round(length * 0.0393701, 2)


@unit(LIGHT_LUX)
def wm2_to_lux(lux: float) -> float:
"""Convert watts per square meter (W/m²) to lux."""
return lux * 127


@unit(UnitOfSpeed.MILES_PER_HOUR)
def ms_to_mph(speed: float) -> float:
"""Convert meters per second (m/s) to miles per hour (mph)."""
Expand Down
2 changes: 2 additions & 0 deletions aiocloudweather/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ class WeathercloudRawSensor:
UnitOfPressure.INHG: inhg_to_hpa,
UnitOfTemperature.FAHRENHEIT: fahrenheit_to_celsius,
UnitOfPrecipitationDepth.INCHES: in_to_mm,
LIGHT_LUX: lux_to_wm2,
UnitOfSpeed.MILES_PER_HOUR: mph_to_ms,
}

METRIC_TO_IMPERIAL: Final = {
UnitOfPressure.HPA: hpa_to_inhg,
UnitOfTemperature.CELSIUS: celsius_to_fahrenheit,
UnitOfPrecipitationDepth.MILLIMETERS: mm_to_in,
UnitOfIrradiance.WATTS_PER_SQUARE_METER: wm2_to_lux,
UnitOfSpeed.METERS_PER_SECOND: ms_to_mph,
}

Expand Down

0 comments on commit a1f39bd

Please sign in to comment.