Repository: home-assistant/core
File: homeassistant/util/unit_conversion.py (Python)

Code before:

class ReactivePowerConverter(BaseUnitConverter):
    """Utility to convert reactive power values."""

    UNIT_CLASS = "reactive_power"
    _UNIT_CONVERSION: dict[str | None, float] = {
        UnitOfReactivePower.MILLIVOLT_AMPERE_REACTIVE: 1 * 1000,
        UnitOfReactivePower.VOLT_AMPERE_REACTIVE: 1,
        UnitOfReactivePower.KILO_VOLT_AMPERE_REACTIVE: 1 / 1000,
    }
    VALID_UNITS = {
        UnitOfReactivePower.MILLIVOLT_AMPERE_REACTIVE,
        UnitOfReactivePower.VOLT_AMPERE_REACTIVE,
        UnitOfReactivePower.KILO_VOLT_AMPERE_REACTIVE,
    }


class OzoneConcentrationConverter(BaseUnitConverter):
    """Convert ozone ratio to mass per volume."""

    UNIT_CLASS = "ozone"
    _UNIT_CONVERSION: dict[str | None, float] = {
        CONCENTRATION_PARTS_PER_BILLION: 1,
        # concentration (µg/m3) = 0.0409 x concentration (ppb) x molar mass
        # Ozone molar mass: 48.00 g/mol
        CONCENTRATION_MICROGRAMS_PER_CUBIC_METER: 0.0409 * 48.00,
    }
    VALID_UNITS = {
        CONCENTRATION_PARTS_PER_BILLION,
        CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
    }


class SpeedConverter(BaseUnitConverter):
    """Utility to convert speed values."""

    UNIT_CLASS = "speed"
    _UNIT_CONVERSION: dict[str | None, float] = {
        UnitOfVolumetricFlux.INCHES_PER_DAY: _DAYS_TO_SECS / _IN_TO_M,
        UnitOfVolumetricFlux.INCHES_PER_HOUR: _HRS_TO_SECS / _IN_TO_M,
        UnitOfVolumetricFlux.MILLIMETERS_PER_DAY: _DAYS_TO_SECS / _MM_TO_M,
        UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR: _HRS_TO_SECS / _MM_TO_M,
        UnitOfSpeed.FEET_PER_SECOND: 1 / _FOOT_TO_M,
        UnitOfSpeed.INCHES_PER_SECOND: 1 / _IN_TO_M,
        UnitOfSpeed.KILOMETERS_PER_HOUR: _HRS_TO_SECS / _KM_TO_M,
        UnitOfSpeed.KNOTS: _HRS_TO_SECS / _NAUTICAL_MILE_TO_M,
        UnitOfSpeed.METERS_PER_MINUTE: _MIN_TO_SEC,
        UnitOfSpeed.METERS_PER_SECOND: 1,
        UnitOfSpeed.MILLIMETERS_PER_SECOND: 1 / _MM_TO_M,
        UnitOfSpeed.MILES_PER_HOUR: _HRS_TO_SECS / _MILE_TO_M,
        UnitOfSpeed.BEAUFORT: 1,

Review comment (suggestion):
I would prefer to use the same pattern as `CarbonMonoxideConcentrationConverter`, with `_OZONE_MOLAR_MASS` defined as a top-level constant

```suggestion
        CONCENTRATION_MICROGRAMS_PER_CUBIC_METER: (
            _OZONE_MOLAR_MASS / _AMBIENT_IDEAL_GAS_MOLAR_VOLUME * 1e6
        ),
```

Code after:
    UNIT_CLASS = "pressure"
    _UNIT_CONVERSION: dict[str | None, float] = {
        UnitOfPressure.MILLIPASCAL: 1 * 1000,
        UnitOfPressure.PA: 1,
        UnitOfPressure.HPA: 1 / 100,
        UnitOfPressure.KPA: 1 / 1000,
        UnitOfPressure.BAR: 1 / 100000,
        UnitOfPressure.CBAR: 1 / 1000,
        UnitOfPressure.MBAR: 1 / 100,
        UnitOfPressure.INHG: 1
        / (_IN_TO_M * 1000 * _STANDARD_GRAVITY * _MERCURY_DENSITY),
        UnitOfPressure.INH2O: 1 / _INH2O_TO_PA,
        UnitOfPressure.PSI: 1 / 6894.757,
        UnitOfPressure.MMHG: 1
        / (_MM_TO_M * 1000 * _STANDARD_GRAVITY * _MERCURY_DENSITY),
    }
    VALID_UNITS = {
        UnitOfPressure.MILLIPASCAL,
        UnitOfPressure.PA,
        UnitOfPressure.HPA,
        UnitOfPressure.KPA,
        UnitOfPressure.BAR,
        UnitOfPressure.CBAR,
        UnitOfPressure.MBAR,
        UnitOfPressure.INHG,
        UnitOfPressure.INH2O,
        UnitOfPressure.PSI,
        UnitOfPressure.MMHG,
    }


class ReactiveEnergyConverter(BaseUnitConverter):
    """Utility to convert reactive energy values."""

    UNIT_CLASS = "reactive_energy"
    _UNIT_CONVERSION: dict[str | None, float] = {
        UnitOfReactiveEnergy.VOLT_AMPERE_REACTIVE_HOUR: 1,
        UnitOfReactiveEnergy.KILO_VOLT_AMPERE_REACTIVE_HOUR: 1 / 1e3,
    }
    VALID_UNITS = set(UnitOfReactiveEnergy)


class ReactivePowerConverter(BaseUnitConverter):
    """Utility to convert reactive power values."""

    UNIT_CLASS = "reactive_power"
    _UNIT_CONVERSION: dict[str | None, float] = {
        UnitOfReactivePower.MILLIVOLT_AMPERE_REACTIVE: 1 * 1000,
        UnitOfReactivePower.VOLT_AMPERE_REACTIVE: 1,
        UnitOfReactivePower.KILO_VOLT_AMPERE_REACTIVE: 1 / 1000,
    }