Skip to content

Commit

Permalink
fix: remove pytz to fix blocking (#2281)
Browse files Browse the repository at this point in the history
closes #2277
  • Loading branch information
Snuffy2 authored Jun 8, 2024
1 parent 88d3871 commit 7cb44b2
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions custom_components/alexa_media/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
For more details about this platform, please refer to the documentation at
https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639
"""

import datetime
import json
import logging
Expand All @@ -24,7 +25,6 @@
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import dt
from packaging import version
import pytz

from . import (
CONF_EMAIL,
Expand Down Expand Up @@ -257,9 +257,9 @@ def __init__(self, coordinator, entity_id, name, media_player_device_id):
self._attr_name = name + " Temperature"
self._attr_device_class = SensorDeviceClass.TEMPERATURE
self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_native_value: Optional[
datetime.datetime
] = parse_temperature_from_coordinator(coordinator, entity_id)
self._attr_native_value: Optional[datetime.datetime] = (
parse_temperature_from_coordinator(coordinator, entity_id)
)
self._attr_native_unit_of_measurement: Optional[str] = UnitOfTemperature.CELSIUS
# This includes "_temperature" because the Alexa entityId is for a physical device
# A single physical device could have multiple HA entities
Expand Down Expand Up @@ -306,12 +306,12 @@ def __init__(
self._attr_name = name + " " + self._sensor_name
self._attr_device_class = self._sensor_name
self._attr_state_class = SensorStateClass.MEASUREMENT
self._attr_native_value: Optional[
datetime.datetime
] = parse_air_quality_from_coordinator(coordinator, entity_id, instance)
self._attr_native_unit_of_measurement: Optional[
str
] = ALEXA_UNIT_CONVERSION.get(unit)
self._attr_native_value: Optional[datetime.datetime] = (
parse_air_quality_from_coordinator(coordinator, entity_id, instance)
)
self._attr_native_unit_of_measurement: Optional[str] = (
ALEXA_UNIT_CONVERSION.get(unit)
)
self._attr_unique_id = entity_id + " " + self._sensor_name
self._attr_icon = ALEXA_ICON_CONVERSION.get(sensor_name, ALEXA_ICON_DEFAULT)
self._attr_device_info = (
Expand Down Expand Up @@ -447,11 +447,11 @@ def _fix_alarm_date_time(self, value):
):
return value
naive_time = dt.parse_datetime(value[1][self._sensor_property])
timezone = pytz.timezone(
timezone = dt.get_time_zone(
self._client._timezone # pylint: disable=protected-access
)
if timezone and naive_time:
value[1][self._sensor_property] = timezone.localize(naive_time)
value[1][self._sensor_property] = naive_time.replace(tzinfo=timezone)
elif not naive_time:
# this is typically an older alarm
value[1][self._sensor_property] = datetime.datetime.fromtimestamp(
Expand Down Expand Up @@ -670,9 +670,11 @@ def __init__(self, client, n_json, account):
"remainingTime",
account,
f"next {self._type}",
"mdi:timer-outline"
if (version.parse(HA_VERSION) >= version.parse("0.113.0"))
else "mdi:timer",
(
"mdi:timer-outline"
if (version.parse(HA_VERSION) >= version.parse("0.113.0"))
else "mdi:timer"
),
)

def _process_state(self, value) -> Optional[datetime.datetime]:
Expand Down

0 comments on commit 7cb44b2

Please sign in to comment.