Skip to content

Commit 33cacf2

Browse files
authored
Add support for TimezoneFinderL class from timezonefinder (pnbruckner#26)
1 parent d7d71b8 commit 33cacf2

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ sudo apt install libatlas3-base
4545

4646
`timezonefinderL==2.0.1`
4747
`timezonefinder`
48+
`timezonefinder<6`
4849
`timezonefinder==4.2.0`
50+
51+
- **tz_finder_class** (*Optional*): Specifies which class to use. Only applies when using `timezonefinder` package. Valid options are `TimezoneFinder` and `TimezoneFinderL`. The default is `TimezoneFinder`.
52+
53+
>Note: Starting with release 4.4.0 the `timezonefinder` package provides two classes to choose from: the original `TimezoneFinder` class, and a new class named `TimezoneFinderL`, which effectively replaces the functionality of the `timezonefinderL` package.
54+
4955
### `device_tracker` platform
5056

5157
- **entity_id**: Entity IDs of watched device tracker devices. Can be a single entity ID, a list of entity IDs, or a string containing multiple entity IDs separated by commas.
@@ -88,7 +94,8 @@ time_zone | The name of the time zone in which the device is located, or `unknow
8894
### Example Full Config
8995
```yaml
9096
composite:
91-
tz_finder: timezonefinderL==2.0.1
97+
tz_finder: timezonefinder<6
98+
tz_finder_class: TimezoneFinderL
9299
device_tracker:
93100
- platform: composite
94101
name: me

custom_components/composite/__init__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313

1414
CONF_TZ_FINDER = "tz_finder"
1515
DEFAULT_TZ_FINDER = "timezonefinderL==4.0.2"
16+
CONF_TZ_FINDER_CLASS = "tz_finder_class"
17+
TZ_FINDER_CLASS_OPTS = ["TimezoneFinder", "TimezoneFinderL"]
1618

1719
CONFIG_SCHEMA = vol.Schema(
1820
{
1921
vol.Optional(DOMAIN, default=dict): vol.Schema(
20-
{vol.Optional(CONF_TZ_FINDER, default=DEFAULT_TZ_FINDER): cv.string}
22+
{
23+
vol.Optional(CONF_TZ_FINDER, default=DEFAULT_TZ_FINDER): cv.string,
24+
vol.Optional(
25+
CONF_TZ_FINDER_CLASS, default=TZ_FINDER_CLASS_OPTS[0]
26+
): vol.In(TZ_FINDER_CLASS_OPTS),
27+
}
2128
),
2229
},
2330
extra=vol.ALLOW_EXTRA,
@@ -48,8 +55,16 @@ def setup(hass, config):
4855

4956
if pkg.split("==")[0].strip().endswith("L"):
5057
from timezonefinderL import TimezoneFinder
51-
else:
58+
59+
tf = TimezoneFinder()
60+
elif config[DOMAIN][CONF_TZ_FINDER_CLASS] == "TimezoneFinder":
5261
from timezonefinder import TimezoneFinder
53-
hass.data[DOMAIN] = TimezoneFinder()
62+
63+
tf = TimezoneFinder()
64+
else:
65+
from timezonefinder import TimezoneFinderL
66+
67+
tf = TimezoneFinderL()
68+
hass.data[DOMAIN] = tf
5469

5570
return True

0 commit comments

Comments
 (0)