mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix workday sensor to honor timezone (#47927)
This commit is contained in:
parent
a1ff45cbf2
commit
6a24ec7a30
@ -1,5 +1,5 @@
|
||||
"""Sensor to indicate whether the current day is a workday."""
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
@ -9,6 +9,7 @@ import voluptuous as vol
|
||||
from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity
|
||||
from homeassistant.const import CONF_NAME, WEEKDAYS
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import homeassistant.util.dt as dt
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -77,7 +78,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
sensor_name = config[CONF_NAME]
|
||||
workdays = config[CONF_WORKDAYS]
|
||||
|
||||
year = (get_date(datetime.today()) + timedelta(days=days_offset)).year
|
||||
year = (get_date(dt.now()) + timedelta(days=days_offset)).year
|
||||
obj_holidays = getattr(holidays, country)(years=year)
|
||||
|
||||
if province:
|
||||
@ -185,7 +186,7 @@ class IsWorkdaySensor(BinarySensorEntity):
|
||||
self._state = False
|
||||
|
||||
# Get ISO day of the week (1 = Monday, 7 = Sunday)
|
||||
date = get_date(datetime.today()) + timedelta(days=self._days_offset)
|
||||
date = get_date(dt.now()) + timedelta(days=self._days_offset)
|
||||
day = date.isoweekday() - 1
|
||||
day_of_week = day_to_string(day)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user