Add worldclock custom format (#36157)

This commit is contained in:
Indu Prakash authored and GitHub committed 2020-06-25 11:41:53 -07:00
1 parent 4aedafc73a
commit 15773cb3e0
2 files changed
+33 -9

No files matched your search

+23 -3
View File
@@ -15,15 +15,35 @@ class TestWorldClockSensor(unittest.TestCase):
self.hass = get_test_home_assistant()
self.time_zone = dt_util.get_time_zone("America/New_York")
def test_time(self):
"""Test the time at a different location."""
config = {"sensor": {"platform": "worldclock", "time_zone": "America/New_York"}}
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
self.addCleanup(self.hass.stop)
def test_time(self):
"""Test the time at a different location."""
state = self.hass.states.get("sensor.worldclock_sensor")
assert state is not None
assert state.state == dt_util.now(time_zone=self.time_zone).strftime("%H:%M")
def test_time_format(self):
"""Test time_format setting."""
time_format = "%a, %b %d, %Y %I:%M %p"
config = {
"sensor": {
"platform": "worldclock",
"time_zone": "America/New_York",
"time_format": time_format,
}
}
assert setup_component(self.hass, "sensor", config)
self.hass.block_till_done()
self.addCleanup(self.hass.stop)
state = self.hass.states.get("sensor.worldclock_sensor")
assert state is not None
assert state.state == dt_util.now(time_zone=self.time_zone).strftime(
time_format
)