Esempio n. 1
0
 def wind_speed(self):
     """Return the wind speed."""
     if self.hass.config.units.is_metric and self._wind_speed:
         return round(
             speed_convert(self._wind_speed, SPEED_MILES_PER_HOUR,
                           SPEED_KILOMETERS_PER_HOUR),
             4,
         )
     return self._wind_speed
Esempio n. 2
0
 def extra_state_attributes(self) -> Mapping[str, Any] | None:
     """Return additional state attributes."""
     cloud_cover = self.cloud_cover
     attrs = {
         ATTR_CLOUD_COVER: cloud_cover,
         ATTR_PRECIPITATION_TYPE: self.precipitation_type,
     }
     if (wind_gust := self.wind_gust) is not None:
         attrs[ATTR_WIND_GUST] = round(
             speed_convert(wind_gust, SPEED_MILES_PER_HOUR,
                           self._wind_speed_unit), 4)
Esempio n. 3
0
 def extra_state_attributes(self) -> Mapping[str, Any] | None:
     """Return additional state attributes."""
     wind_gust = self.wind_gust
     if wind_gust and self.hass.config.units.is_metric:
         wind_gust = round(
             speed_convert(self.wind_gust, SPEED_MILES_PER_HOUR,
                           SPEED_KILOMETERS_PER_HOUR),
             4,
         )
     cloud_cover = self.cloud_cover
     return {
         ATTR_CLOUD_COVER: cloud_cover,
         ATTR_WIND_GUST: wind_gust,
         ATTR_PRECIPITATION_TYPE: self.precipitation_type,
     }
Esempio n. 4
0
    def _forecast_dict(
        self,
        forecast_dt: datetime,
        use_datetime: bool,
        condition: int | str,
        precipitation: float | None,
        precipitation_probability: float | None,
        temp: float | None,
        temp_low: float | None,
        wind_direction: float | None,
        wind_speed: float | None,
    ) -> dict[str, Any]:
        """Return formatted Forecast dict from ClimaCell forecast data."""
        if use_datetime:
            translated_condition = self._translate_condition(
                condition, is_up(self.hass, forecast_dt)
            )
        else:
            translated_condition = self._translate_condition(condition, True)

        if self.hass.config.units.is_metric:
            if precipitation:
                precipitation = round(
                    distance_convert(precipitation / 12, LENGTH_FEET, LENGTH_METERS)
                    * 1000,
                    4,
                )
            if wind_speed:
                wind_speed = round(
                    speed_convert(
                        wind_speed, SPEED_MILES_PER_HOUR, SPEED_KILOMETERS_PER_HOUR
                    ),
                    4,
                )

        data = {
            ATTR_FORECAST_TIME: forecast_dt.isoformat(),
            ATTR_FORECAST_CONDITION: translated_condition,
            ATTR_FORECAST_PRECIPITATION: precipitation,
            ATTR_FORECAST_PRECIPITATION_PROBABILITY: precipitation_probability,
            ATTR_FORECAST_TEMP: temp,
            ATTR_FORECAST_TEMP_LOW: temp_low,
            ATTR_FORECAST_WIND_BEARING: wind_direction,
            ATTR_FORECAST_WIND_SPEED: wind_speed,
        }

        return {k: v for k, v in data.items() if v is not None}
Esempio n. 5
0
     unit_metric=LENGTH_KILOMETERS,
     imperial_conversion=lambda val: distance_convert(
         val, LENGTH_KILOMETERS, LENGTH_MILES),
 ),
 TomorrowioSensorEntityDescription(
     key=TMRW_ATTR_CLOUD_COVER,
     name="Cloud Cover",
     native_unit_of_measurement=PERCENTAGE,
 ),
 # Data comes in as m/s, convert to mi/h for imperial
 TomorrowioSensorEntityDescription(
     key=TMRW_ATTR_WIND_GUST,
     name="Wind Gust",
     unit_imperial=SPEED_MILES_PER_HOUR,
     unit_metric=SPEED_METERS_PER_SECOND,
     imperial_conversion=lambda val: speed_convert(
         val, SPEED_METERS_PER_SECOND, SPEED_MILES_PER_HOUR),
 ),
 TomorrowioSensorEntityDescription(
     key=TMRW_ATTR_PRECIPITATION_TYPE,
     name="Precipitation Type",
     value_map=PrecipitationType,
     device_class="tomorrowio__precipitation_type",
     icon="mdi:weather-snowy-rainy",
 ),
 # Data comes in as ppb, convert to µg/m^3
 # Molecular weight of Ozone is 48
 TomorrowioSensorEntityDescription(
     key=TMRW_ATTR_OZONE,
     name="Ozone",
     native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
     multiplication_factor=convert_ppb_to_ugm3(48),