Make Netatmo use async pyatmo (#49717)
* Split initialization from data retrival * Await class initialization * Async camera * More async * Remove stale code * Clean up * Update tests * Fix test * Improve error handling * Bump pyatmo version to 5.0.0 * Add tests * Add cloudhook test * Increase coverage * Add test with no camera devices * Add test for ApiError * Add test for timeout * Clean up * Catch pyatmo ApiError * Fix PublicData * Fix media source bug * Increase coverage for light * Test webhook with delayed start * Increase coverage * Clean up leftover data classes * Make nonprivate * Review comments * Clean up stale code * Increase cov * Clean up code * Code clean up * Revert delay * Update homeassistant/components/netatmo/climate.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/netatmo/sensor.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Address comment * Raise cov Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
e06a2a53c4
commit
ceec871340
21 changed files with 846 additions and 476 deletions
|
@ -1,8 +1,6 @@
|
|||
"""Support for the Netatmo camera lights."""
|
||||
import logging
|
||||
|
||||
import pyatmo
|
||||
|
||||
from homeassistant.components.light import LightEntity
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
@ -34,41 +32,29 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
await data_handler.register_data_class(
|
||||
CAMERA_DATA_CLASS_NAME, CAMERA_DATA_CLASS_NAME, None
|
||||
)
|
||||
data_class = data_handler.data.get(CAMERA_DATA_CLASS_NAME)
|
||||
|
||||
if CAMERA_DATA_CLASS_NAME not in data_handler.data:
|
||||
if not data_class or data_class.raw_data == {}:
|
||||
raise PlatformNotReady
|
||||
|
||||
async def get_entities():
|
||||
"""Retrieve Netatmo entities."""
|
||||
all_cameras = []
|
||||
for home in data_handler.data[CAMERA_DATA_CLASS_NAME].cameras.values():
|
||||
for camera in home.values():
|
||||
all_cameras.append(camera)
|
||||
|
||||
entities = []
|
||||
all_cameras = []
|
||||
entities = [
|
||||
NetatmoLight(
|
||||
data_handler,
|
||||
camera["id"],
|
||||
camera["type"],
|
||||
camera["home_id"],
|
||||
)
|
||||
for camera in all_cameras
|
||||
if camera["type"] == "NOC"
|
||||
]
|
||||
|
||||
try:
|
||||
for home in data_handler.data[CAMERA_DATA_CLASS_NAME].cameras.values():
|
||||
for camera in home.values():
|
||||
all_cameras.append(camera)
|
||||
|
||||
except pyatmo.NoDevice:
|
||||
_LOGGER.debug("No cameras found")
|
||||
|
||||
for camera in all_cameras:
|
||||
if camera["type"] == "NOC":
|
||||
_LOGGER.debug("Adding camera light %s %s", camera["id"], camera["name"])
|
||||
entities.append(
|
||||
NetatmoLight(
|
||||
data_handler,
|
||||
camera["id"],
|
||||
camera["type"],
|
||||
camera["home_id"],
|
||||
)
|
||||
)
|
||||
|
||||
return entities
|
||||
|
||||
async_add_entities(await get_entities(), True)
|
||||
|
||||
await data_handler.unregister_data_class(CAMERA_DATA_CLASS_NAME, None)
|
||||
_LOGGER.debug("Adding camera lights %s", entities)
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
class NetatmoLight(NetatmoBase, LightEntity):
|
||||
|
@ -136,19 +122,19 @@ class NetatmoLight(NetatmoBase, LightEntity):
|
|||
"""Return true if light is on."""
|
||||
return self._is_on
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn camera floodlight on."""
|
||||
_LOGGER.debug("Turn camera '%s' on", self._name)
|
||||
self._data.set_state(
|
||||
await self._data.async_set_state(
|
||||
home_id=self._home_id,
|
||||
camera_id=self._id,
|
||||
floodlight="on",
|
||||
)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn camera floodlight into auto mode."""
|
||||
_LOGGER.debug("Turn camera '%s' to auto mode", self._name)
|
||||
self._data.set_state(
|
||||
await self._data.async_set_state(
|
||||
home_id=self._home_id,
|
||||
camera_id=self._id,
|
||||
floodlight="auto",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue