Skip to content

Commit

Permalink
Add: More debug logs for motion sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Apr 22, 2021
1 parent dd82d8a commit 968bbad
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion custom_components/tapo_control/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.core import callback
from .const import DOMAIN
from .const import DOMAIN, LOGGER
from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry
from homeassistant.util import slugify
Expand All @@ -12,6 +12,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:


async def async_setup_entry(hass, entry, async_add_entities):
LOGGER.debug("Setting up binary sensor for motion.")
events = hass.data[DOMAIN][entry.entry_id]["events"]
name = hass.data[DOMAIN][entry.entry_id]["name"]
camData = hass.data[DOMAIN][entry.entry_id]["camData"]
Expand All @@ -20,16 +21,22 @@ async def async_setup_entry(hass, entry, async_add_entities):
for event in events.get_platform("binary_sensor")
}

LOGGER.debug("Adding binary sensor entity.")
async_add_entities(entities.values())

@callback
def async_check_entities():
LOGGER.debug("async_check_entities")
new_entities = []
LOGGER.debug("Looping through available events.")
for event in events.get_platform("binary_sensor"):
LOGGER.debug(event)
if event.uid not in entities:
LOGGER.debug("Found event which doesn't have entity yet, creating it.")
entities[event.uid] = TapoBinarySensor(event.uid, events, name, camData)
new_entities.append(entities[event.uid])
async_add_entities(new_entities)
LOGGER.debug(new_entities)

events.async_add_listener(async_check_entities)

Expand All @@ -38,12 +45,14 @@ def async_check_entities():

class TapoBinarySensor(BinarySensorEntity):
def __init__(self, uid, events, name, camData):
LOGGER.debug("TapoBinarySensor - init - start")
self._name = name
self._attributes = camData["basic_info"]
BinarySensorEntity.__init__(self)

self.uid = uid
self.events = events
LOGGER.debug("TapoBinarySensor - init - end")

@property
def is_on(self) -> bool:
Expand Down

0 comments on commit 968bbad

Please sign in to comment.