Skip to content

Commit

Permalink
Fix #213: Error adding entities for domain select and switch
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Oct 18, 2022
1 parent 672bdb5 commit e3c4921
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 34 deletions.
23 changes: 15 additions & 8 deletions custom_components/tapo_control/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@ async def async_setup_entry(
entry = hass.data[DOMAIN][config_entry.entry_id]

selects = []
LOGGER.debug("Adding TapoNightVisionSelect...")
selects.append(TapoNightVisionSelect(entry, hass, config_entry))
LOGGER.debug("Adding TapoAutomaticAlarmModeSelect...")
selects.append(TapoAutomaticAlarmModeSelect(entry, hass, config_entry))
LOGGER.debug("Adding TapoLightFrequencySelect...")
selects.append(TapoLightFrequencySelect(entry, hass, config_entry))
selects.append(
await check_and_create(
entry, hass, TapoMotionDetectionSelect, "getAutoTrackTarget", config_entry
)

tapoMotionDetectionSelect = await check_and_create(
entry, hass, TapoMotionDetectionSelect, "getAutoTrackTarget", config_entry
)
selects.append(
await check_and_create(
entry, hass, TapoMoveToPresetSelect, "getPresets", config_entry
)
if tapoMotionDetectionSelect:
LOGGER.debug("Adding TapoMotionDetectionSelect...")
selects.append(tapoMotionDetectionSelect)

tapoMoveToPresetSelect = await check_and_create(
entry, hass, TapoMoveToPresetSelect, "getPresets", config_entry
)
if tapoMoveToPresetSelect:
LOGGER.debug("Adding TapoMoveToPresetSelect...")
selects.append(tapoMoveToPresetSelect)

async_add_entities(selects)

Expand Down
66 changes: 40 additions & 26 deletions custom_components/tapo_control/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,51 @@ async def async_setup_entry(
entry: dict = hass.data[DOMAIN][config_entry.entry_id]

switches = []
switches.append(
await check_and_create(
entry, hass, TapoPrivacySwitch, "getPrivacyMode", config_entry
)

tapoPrivacySwitch = await check_and_create(
entry, hass, TapoPrivacySwitch, "getPrivacyMode", config_entry
)
switches.append(
await check_and_create(
entry,
hass,
TapoLensDistortionCorrectionSwitch,
"getLensDistortionCorrection",
config_entry,
)
if tapoPrivacySwitch:
LOGGER.debug("Adding tapoPrivacySwitch...")
switches.append(tapoPrivacySwitch)

tapoLensDistortionCorrectionSwitch = await check_and_create(
entry,
hass,
TapoLensDistortionCorrectionSwitch,
"getLensDistortionCorrection",
config_entry,
)
switches.append(
await check_and_create(
entry, hass, TapoIndicatorLedSwitch, "getLED", config_entry
)
)
switches.append(
await check_and_create(
entry, hass, TapoFlipSwitch, "getImageFlipVertical", config_entry
)
if tapoLensDistortionCorrectionSwitch:
LOGGER.debug("Adding tapoLensDistortionCorrectionSwitch...")
switches.append(tapoLensDistortionCorrectionSwitch)

tapoIndicatorLedSwitch = await check_and_create(
entry, hass, TapoIndicatorLedSwitch, "getLED", config_entry
)
switches.append(
await check_and_create(
entry, hass, TapoAutoTrackSwitch, "getAutoTrackTarget", config_entry
)
if tapoIndicatorLedSwitch:
LOGGER.debug("Adding tapoIndicatorLedSwitch...")
switches.append(tapoIndicatorLedSwitch)

tapoFlipSwitch = await check_and_create(
entry, hass, TapoFlipSwitch, "getImageFlipVertical", config_entry
)
if tapoFlipSwitch:
LOGGER.debug("Adding tapoFlipSwitch...")
switches.append(tapoFlipSwitch)

async_add_entities(switches)
tapoAutoTrackSwitch = await check_and_create(
entry, hass, TapoAutoTrackSwitch, "getAutoTrackTarget", config_entry
)
if tapoAutoTrackSwitch:
LOGGER.debug("Adding tapoAutoTrackSwitch...")
switches.append(tapoAutoTrackSwitch)

if switches:
LOGGER.debug("Adding switch entities...")
async_add_entities(switches)
else:
LOGGER.debug("No switch entities available.")


class TapoLensDistortionCorrectionSwitch(TapoSwitchEntity):
Expand Down

0 comments on commit e3c4921

Please sign in to comment.