# Buggy code
def _update_recurring_alarm(self, value):
    _LOGGER.debug("value %s", value)
    alarm = value[1][self._sensor_property]
    alarm_on = value[1]["status"] == "ON"
    recurring_pattern = value[1]["recurringPattern"]
    while (
        alarm_on
        and recurring_pattern
        and alarm < dt.now()
        and RECURRING_PATTERN_ISO_SET[recurring_pattern]
        and alarm.isoweekday not in RECURRING_PATTERN_ISO_SET[recurring_pattern]
    ):
        alarm += datetime.timedelta(days=1)
    if alarm != value[1][self._sensor_property]:
        _LOGGER.debug(
            "Alarm with recurrence %s set to %s",
            RECURRING_PATTERN[recurring_pattern],
            alarm,
        )
        value[1][self._sensor_property] = alarm
    return value


# Traceback (TypeError)
2020-03-26 22:05:03 DEBUG (MainThread) [custom_components.alexa_media.sensor] value ('xxxxx', {'alarmTime': 1585325040000, 'automationId': None, 'createdDate': 1519416302707, 'deferredAtTime': None, 'deliveryType': None, 'deviceName': None, 'deviceSerialNumber': 'xxxxxx', 'deviceType': 'xxxxx', 'extensibleAttribute': None, 'geoLocationTriggerData': None, 'id': 'xxxxxx_REMINDER', 'lastOccurrenceTimeInMilli': 0, 'lastUpdatedDate': 0, 'musicAlarmId': None, 'musicEntity': None, 'notificationIndex': 'xxxxx-07d5-469c-b04c-bc54b39aafcf', 'originalDate': '2020-03-27', 'originalTime': '09:04:00.000', 'personProfile': None, 'provider': None, 'rRuleData': {'byMonthDays': None, 'byWeekDays': None, 'flexibleRecurringPatternType': 'ONCE_A_DAY', 'frequency': None, 'intervals': [1], 'nextTriggerTimes': None, 'notificationTimes': ['09:04:00.000'], 'recurEndDate': None, 'recurEndTime': None, 'recurStartDate': None, 'recurStartTime': None, 'recurrenceRules': ['FREQ=DAILY;BYHOUR=9;BYMINUTE=4;BYSECOND=0;INTERVAL=1;']}, 'recurrenceEligibility': False, 'recurringPattern': 'P1D', 'remainingTime': 0, 'reminderAppLabel': None, 'reminderLabel': 'Take your vitamins', 'reminderSubLabel': None, 'skillInfo': None, 'snoozedToTime': None, 'sound': {'displayName': 'Simple Alarm', 'folder': None, 'id': 'system_alerts_melodic_01', 'providerId': 'ECHO', 'sampleUrl': 'https://s3.amazonaws.com/deeappservice.prod.notificationtones/system_alerts_melodic_01.mp3'}, 'status': 'ON', 'targetPersonProfiles': None, 'timeZoneId': None, 'timerLabel': None, 'tmwNotificationProperties': None, 'triggerTime': 0, 'type': 'Reminder', 'version': '3189', 'date_time': '2020-03-27 09:04:00.000'})
2020-03-26 22:05:03 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up alexa_media platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
return fut.result()
File "/config/custom_components/alexa_media/sensor.py", line 151, in async_setup_entry
hass, config_entry.data, async_add_devices, discovery_info=None
File "/config/custom_components/alexa_media/helpers.py", line 111, in wrapper
result = await func(*args, **kwargs)
File "/config/custom_components/alexa_media/sensor.py", line 118, in async_setup_platform
account,
File "/config/custom_components/alexa_media/sensor.py", line 467, in __init__
client, n_json, "alarmTime", account, f"next {self._type}", "mdi:reminder"
File "/config/custom_components/alexa_media/sensor.py", line 192, in __init__
self._process_raw_notifications()
File "/config/custom_components/alexa_media/sensor.py", line 200, in _process_raw_notifications
self._all = list(map(self._update_recurring_alarm, self._all))
File "/config/custom_components/alexa_media/sensor.py", line 253, in _update_recurring_alarm
and alarm < dt.now()
TypeError: '<' not supported between instances of 'int' and 'datetime.datetime'

# Fixed code
def _update_recurring_alarm(self, value):
    _LOGGER.debug("value %s", value)
    alarm = value[1][self._sensor_property]
    reminder = None
    if isinstance(value[1][self._sensor_property], int):
        reminder = True
        alarm = dt.as_local(
            self._round_time(
                datetime.datetime.fromtimestamp(alarm / 1000, tz=LOCAL_TIMEZONE)
            )
        )
    alarm_on = value[1]["status"] == "ON"
    recurring_pattern = value[1]["recurringPattern"]
    while (
        alarm_on
        and recurring_pattern
        and RECURRING_PATTERN_ISO_SET[recurring_pattern]
        and alarm.isoweekday not in RECURRING_PATTERN_ISO_SET[recurring_pattern]
        and alarm < dt.now()
    ):
        alarm += datetime.timedelta(days=1)
    if reminder:
        alarm = dt.as_timestamp(alarm) * 1000
    if alarm != value[1][self._sensor_property]:
        _LOGGER.debug(
            "%s with recurrence %s set to %s",
            value[1]["type"],
            RECURRING_PATTERN[recurring_pattern],
            alarm,
        )
        value[1][self._sensor_property] = alarm
    return value