1 """Support for showing the time in a different time zone."""
3 from __future__
import annotations
5 from datetime
import tzinfo
7 import voluptuous
as vol
10 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
23 from .const
import CONF_TIME_FORMAT, DEFAULT_NAME, DEFAULT_TIME_STR_FORMAT, DOMAIN
25 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
27 vol.Required(CONF_TIME_ZONE): cv.time_zone,
28 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
29 vol.Optional(CONF_TIME_FORMAT, default=DEFAULT_TIME_STR_FORMAT): cv.string,
37 async_add_entities: AddEntitiesCallback,
38 discovery_info: DiscoveryInfoType |
None =
None,
40 """Set up the World clock sensor."""
41 hass.async_create_task(
42 hass.config_entries.flow.async_init(
44 context={
"source": SOURCE_IMPORT},
52 f
"deprecated_yaml_{DOMAIN}",
53 breaks_in_ha_version=
"2025.2.0",
56 severity=IssueSeverity.WARNING,
57 translation_key=
"deprecated_yaml",
58 translation_placeholders={
60 "integration_title":
"Worldclock",
68 async_add_entities: AddEntitiesCallback,
70 """Set up the World clock sensor entry."""
71 time_zone = await dt_util.async_get_time_zone(entry.options[CONF_TIME_ZONE])
76 entry.options[CONF_NAME],
77 entry.options[CONF_TIME_FORMAT],
86 """Representation of a World clock sensor."""
88 _attr_icon =
"mdi:clock"
89 _attr_has_entity_name =
True
93 self, time_zone: tzinfo |
None, name: str, time_format: str, unique_id: str
95 """Initialize the sensor."""
100 identifiers={(DOMAIN, unique_id)},
102 entry_type=DeviceEntryType.SERVICE,
103 manufacturer=
"Worldclock",
107 """Get the time and updates the states."""
None __init__(self, tzinfo|None time_zone, str name, str time_format, str unique_id)
None async_create_issue(HomeAssistant hass, str entry_id)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)