Skip to content

Commit f6da5a0

Browse files
authored
Merge pull request #58 from t-animal/master
Expose switch for sun automatic in rollotrons
2 parents 2c2eb22 + 7d0c839 commit f6da5a0

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

custom_components/duofern/switch.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,25 @@ async def async_setup_entry(
3030
_LOGGER.info("switch: already added: " + str(stick.config['devices']))
3131

3232
to_add: List[SwitchEntity] = []
33-
for duofernDevice in stick.config['devices']:
34-
duofernId: str = duofernDevice['id']
35-
subId = "manualMode"
36-
if not is_shutter(duofernId):
37-
_LOGGER.info("switch: skipping: " + str(duofernId) + " because it is not a shutter")
38-
continue
39-
40-
if isDeviceSetUp(hass, duofernId, subId):
41-
_LOGGER.info("switch: skipping: " + str(duofernId) + " because it is is already set up")
42-
continue
4333

44-
switch = DuofernShutterConfigurableSwitch(duofernId, stick, "manualMode", "Manual Mode", "manual_mode")
45-
to_add.append(switch)
46-
saveDeviceAsSetUp(hass, switch, duofernId, subId)
34+
shutterSwitches = {
35+
"manualMode": ["manualMode", "Manual Mode", "manual_mode"],
36+
"sunAutomatic": ["sunAutomatic", "Sun Automatic", "sun_automatic"]
37+
}
38+
for subId, [command, nameSuffix, idSuffix] in shutterSwitches.entries():
39+
for duofernDevice in stick.config['devices']:
40+
duofernId: str = duofernDevice['id']
41+
if not is_shutter(duofernId):
42+
_LOGGER.info("switch: skipping: " + str(duofernId) + " because it is not a shutter")
43+
continue
44+
45+
if isDeviceSetUp(hass, duofernId, subId):
46+
_LOGGER.info("switch: skipping: " + str(duofernId) + " because it is is already set up")
47+
continue
48+
49+
switch = DuofernShutterConfigurableSwitch(duofernId, stick, command, nameSuffix, idSuffix)
50+
to_add.append(switch)
51+
saveDeviceAsSetUp(hass, switch, duofernId, subId)
4752

4853
async_add_entities(to_add)
4954

0 commit comments

Comments
 (0)