Skip to content

Commit

Permalink
Merge pull request #3 from siamzam/accuweather-define-a-constant-inst…
Browse files Browse the repository at this point in the history
…ead-of-duplicating-string-literals

Accuweather - refactored duplicated string literals
  • Loading branch information
siamzam committed Oct 10, 2023
2 parents c56b768 + 5933e6f commit daa868a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions homeassistant/components/accuweather/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
)

PARALLEL_UPDATES = 1
STR_CLOUDY_WEATHER = "mdi:weather-cloudy"
STR_SUNNY_WEATHER = "mdi:weather-sunny"


@dataclass
Expand Down Expand Up @@ -78,7 +80,7 @@ class AccuWeatherSensorDescription(
*(
AccuWeatherSensorDescription(
key="CloudCoverDay",
icon="mdi:weather-cloudy",
icon=STR_CLOUDY_WEATHER,
entity_registry_enabled_default=False,
native_unit_of_measurement=PERCENTAGE,
value_fn=lambda data: cast(int, data),
Expand All @@ -90,7 +92,7 @@ class AccuWeatherSensorDescription(
*(
AccuWeatherSensorDescription(
key="CloudCoverNight",
icon="mdi:weather-cloudy",
icon=STR_CLOUDY_WEATHER,
entity_registry_enabled_default=False,
native_unit_of_measurement=PERCENTAGE,
value_fn=lambda data: cast(int, data),
Expand Down Expand Up @@ -216,7 +218,7 @@ class AccuWeatherSensorDescription(
*(
AccuWeatherSensorDescription(
key="SolarIrradianceDay",
icon="mdi:weather-sunny",
icon=STR_SUNNY_WEATHER,
entity_registry_enabled_default=False,
native_unit_of_measurement=UnitOfIrradiance.WATTS_PER_SQUARE_METER,
value_fn=lambda data: cast(float, data[ATTR_VALUE]),
Expand All @@ -228,7 +230,7 @@ class AccuWeatherSensorDescription(
*(
AccuWeatherSensorDescription(
key="SolarIrradianceNight",
icon="mdi:weather-sunny",
icon=STR_SUNNY_WEATHER,
entity_registry_enabled_default=False,
native_unit_of_measurement=UnitOfIrradiance.WATTS_PER_SQUARE_METER,
value_fn=lambda data: cast(float, data[ATTR_VALUE]),
Expand Down Expand Up @@ -275,7 +277,7 @@ class AccuWeatherSensorDescription(
*(
AccuWeatherSensorDescription(
key="UVIndex",
icon="mdi:weather-sunny",
icon=STR_SUNNY_WEATHER,
native_unit_of_measurement=UV_INDEX,
value_fn=lambda data: cast(int, data[ATTR_VALUE]),
attr_fn=lambda data: {ATTR_LEVEL: data[ATTR_CATEGORY]},
Expand Down Expand Up @@ -358,7 +360,7 @@ class AccuWeatherSensorDescription(
),
AccuWeatherSensorDescription(
key="CloudCover",
icon="mdi:weather-cloudy",
icon=STR_CLOUDY_WEATHER,
entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
Expand Down Expand Up @@ -410,7 +412,7 @@ class AccuWeatherSensorDescription(
),
AccuWeatherSensorDescription(
key="UVIndex",
icon="mdi:weather-sunny",
icon=STR_SUNNY_WEATHER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UV_INDEX,
value_fn=lambda data: cast(int, data),
Expand Down

0 comments on commit daa868a

Please sign in to comment.