Repository: home-assistant/core
File: homeassistant/components/ecowitt/sensor.py (Python)

Code before:

from . import EcowittConfigEntry
from .entity import EcowittEntity

_METRIC: Final = (
    EcoWittSensorTypes.TEMPERATURE_C,
    EcoWittSensorTypes.RAIN_COUNT_MM,
    EcoWittSensorTypes.RAIN_RATE_MM,
    EcoWittSensorTypes.LIGHTNING_DISTANCE_KM,
    EcoWittSensorTypes.SPEED_KPH,
    EcoWittSensorTypes.PRESSURE_HPA,
)
_IMPERIAL: Final = (
    EcoWittSensorTypes.TEMPERATURE_F,
    EcoWittSensorTypes.RAIN_COUNT_INCHES,
    EcoWittSensorTypes.RAIN_RATE_INCHES,
    EcoWittSensorTypes.LIGHTNING_DISTANCE_MILES,
    EcoWittSensorTypes.SPEED_MPH,
    EcoWittSensorTypes.PRESSURE_INHG,
)


# Hourly and 24h rain count sensors are rolling window sensors
_ROLLING_WINDOW_RAIN_COUNT_SENSOR = re.compile(
    "(?:hourly|last24h)rain(?:in|mm)|(?:last24)?hrain_piezo(?:mm)?"
)


ECOWITT_SENSORS_MAPPING: Final = {
    EcoWittSensorTypes.HUMIDITY: SensorEntityDescription(
        key="HUMIDITY",
        device_class=SensorDeviceClass.HUMIDITY,
        native_unit_of_measurement=PERCENTAGE,
        state_class=SensorStateClass.MEASUREMENT,
    ),
    EcoWittSensorTypes.DEGREE: SensorEntityDescription(
        key="DEGREE",
        native_unit_of_measurement=DEGREE,
        device_class=SensorDeviceClass.WIND_DIRECTION,
        state_class=SensorStateClass.MEASUREMENT_ANGLE,
    ),
    EcoWittSensorTypes.WATT_METERS_SQUARED: SensorEntityDescription(
        key="WATT_METERS_SQUARED",
        device_class=SensorDeviceClass.IRRADIANCE,
        native_unit_of_measurement=UnitOfIrradiance.WATTS_PER_SQUARE_METER,
        state_class=SensorStateClass.MEASUREMENT,
    ),
    EcoWittSensorTypes.UV_INDEX: SensorEntityDescription(
        key="UV_INDEX",
        native_unit_of_measurement=UV_INDEX,
        state_class=SensorStateClass.MEASUREMENT,

Review comment (suggestion):
The list is not that extensive, I'd prefer this, as it's not only much easier to comprehend (even with the comment, it took me some time to understand what sensors it matches), it's less complex as well.
```suggestion
_ROLLING_WINDOW_RAIN_COUNT_SENSORS = {
  "hourlyrainin",
  "hourlyrainmm",
  "last24hrainin",
  "last24hrainmm",
  "hrain_piezo",
  "hrain_piezomm",
  "last24hrain_piezo",
  "last24hrain_piezomm",
}
```

Code after:

from . import EcowittConfigEntry
from .entity import EcowittEntity

_LOGGER = logging.getLogger(__name__)


_METRIC: Final = (
    EcoWittSensorTypes.TEMPERATURE_C,
    EcoWittSensorTypes.RAIN_COUNT_MM,
    EcoWittSensorTypes.RAIN_RATE_MM,
    EcoWittSensorTypes.LIGHTNING_DISTANCE_KM,
    EcoWittSensorTypes.SPEED_KPH,
    EcoWittSensorTypes.PRESSURE_HPA,
)
_IMPERIAL: Final = (
    EcoWittSensorTypes.TEMPERATURE_F,
    EcoWittSensorTypes.RAIN_COUNT_INCHES,
    EcoWittSensorTypes.RAIN_RATE_INCHES,
    EcoWittSensorTypes.LIGHTNING_DISTANCE_MILES,
    EcoWittSensorTypes.SPEED_MPH,
    EcoWittSensorTypes.PRESSURE_INHG,
)


_RAIN_COUNT_SENSORS_STATE_CLASS_MAPPING: Final = {
    "eventrainin": SensorStateClass.TOTAL_INCREASING,
    "hourlyrainin": None,
    "totalrainin": SensorStateClass.TOTAL_INCREASING,
    "dailyrainin": SensorStateClass.TOTAL_INCREASING,
    "weeklyrainin": SensorStateClass.TOTAL_INCREASING,
    "monthlyrainin": SensorStateClass.TOTAL_INCREASING,
    "yearlyrainin": SensorStateClass.TOTAL_INCREASING,
    "last24hrainin": None,
    "eventrainmm": SensorStateClass.TOTAL_INCREASING,
    "hourlyrainmm": None,
    "totalrainmm": SensorStateClass.TOTAL_INCREASING,
    "dailyrainmm": SensorStateClass.TOTAL_INCREASING,
    "weeklyrainmm": SensorStateClass.TOTAL_INCREASING,
    "monthlyrainmm": SensorStateClass.TOTAL_INCREASING,
    "yearlyrainmm": SensorStateClass.TOTAL_INCREASING,
    "last24hrainmm": None,
    "erain_piezo": SensorStateClass.TOTAL_INCREASING,
    "hrain_piezo": None,
    "drain_piezo": SensorStateClass.TOTAL_INCREASING,
    "wrain_piezo": SensorStateClass.TOTAL_INCREASING,
    "mrain_piezo": SensorStateClass.TOTAL_INCREASING,
    "yrain_piezo": SensorStateClass.TOTAL_INCREASING,
    "last24hrain_piezo": None,
    "erain_piezomm": SensorStateClass.TOTAL_INCREASING,
    "hrain_piezomm": None,