-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combine Cloud and Local versions of the Dyson Integration (#50)
* Improving the readme. * Updating config flow for more clarity * Merge Dyson Cloud into ha-dyson
- Loading branch information
Showing
8 changed files
with
396 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Support for Dyson cloud account.""" | ||
|
||
import asyncio | ||
import logging | ||
from functools import partial | ||
|
||
from homeassistant.exceptions import ConfigEntryNotReady | ||
from ..vendor.libdyson.cloud.account import DysonAccountCN | ||
from ..vendor.libdyson.cloud.device_info import DysonDeviceInfo | ||
from ..vendor.libdyson.const import DEVICE_TYPE_360_EYE | ||
from ..vendor.libdyson.discovery import DysonDiscovery | ||
from ..vendor.libdyson.dyson_device import DysonDevice | ||
from ..vendor.libdyson.exceptions import DysonException, DysonNetworkError | ||
from homeassistant.config_entries import ConfigEntry, SOURCE_DISCOVERY | ||
from homeassistant.const import CONF_HOST, EVENT_HOMEASSISTANT_STOP | ||
from homeassistant.core import HomeAssistant, callback | ||
from homeassistant.helpers.entity import Entity | ||
from homeassistant.components.zeroconf import async_get_instance | ||
from ..vendor.libdyson.cloud import DysonAccount | ||
from custom_components.dyson_local import DOMAIN as DYSON_LOCAL_DOMAIN | ||
|
||
from .const import CONF_AUTH, CONF_REGION, DATA_ACCOUNT, DATA_DEVICES, DOMAIN | ||
|
||
_LOGGER = logging.getLogger(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
"""Camera platform for Dyson cloud.""" | ||
from typing import Callable | ||
import logging | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.components.camera import Camera | ||
from ..vendor.libdyson.const import DEVICE_TYPE_360_EYE, DEVICE_TYPE_360_HEURIST | ||
from ..vendor.libdyson.cloud.cloud_360_eye import DysonCloud360Eye | ||
from ..vendor.libdyson.cloud import DysonDeviceInfo | ||
from datetime import timedelta | ||
|
||
from .const import DATA_ACCOUNT, DATA_DEVICES, DOMAIN | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
SCAN_INTERVAL = timedelta(minutes=30) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: Callable | ||
) -> None: | ||
"""Set up Dyson fan from a config entry.""" | ||
data = hass.data[DOMAIN][config_entry.entry_id] | ||
account = data[DATA_ACCOUNT] | ||
devices = data[DATA_DEVICES] | ||
entities = [] | ||
for device in devices: | ||
if device.product_type not in [DEVICE_TYPE_360_EYE]: | ||
continue | ||
entities.append(DysonCleaningMapEntity( | ||
DysonCloud360Eye(account, device.serial), | ||
device, | ||
)) | ||
async_add_entities(entities, True) | ||
|
||
|
||
class DysonCleaningMapEntity(Camera): | ||
"""Dyson vacuum cleaning map entity.""" | ||
|
||
def __init__(self, device: DysonCloud360Eye, device_info: DysonDeviceInfo): | ||
super().__init__() | ||
self._device = device | ||
self._device_info = device_info | ||
self._last_cleaning_task = None | ||
self._image = None | ||
|
||
@property | ||
def name(self) -> str: | ||
"""Return entity name.""" | ||
return f"{self._device_info.name} Cleaning Map" | ||
|
||
@property | ||
def unique_id(self) -> str: | ||
"""Return entity unique id.""" | ||
return self._device_info.serial | ||
|
||
@property | ||
def device_info(self) -> dict: | ||
"""Return device info of the entity.""" | ||
return { | ||
"identifiers": {(DOMAIN, self._device_info.serial)}, | ||
"name": self._device_info.name, | ||
"manufacturer": "Dyson", | ||
"model": self._device_info.product_type, | ||
"sw_version": self._device_info.version, | ||
} | ||
|
||
@property | ||
def icon(self) -> str: | ||
"""Return entity icon.""" | ||
return "mdi:map" | ||
|
||
def camera_image(self): | ||
"""Return cleaning map.""" | ||
return self._image | ||
|
||
def update(self): | ||
"""Check for map update.""" | ||
_LOGGER.debug("Running cleaning map update for %s", self._device_info.name) | ||
cleaning_tasks = self._device.get_cleaning_history() | ||
|
||
last_task = None | ||
for task in cleaning_tasks: | ||
if task.area > 0.0: | ||
# Skip cleaning tasks with 0 area, map not available | ||
last_task = task | ||
break | ||
if last_task is None: | ||
_LOGGER.debug("No cleaning history found.") | ||
self._last_cleaning_task = None | ||
return | ||
|
||
if last_task == self._last_cleaning_task: | ||
_LOGGER.debug("Cleaning task not changed. Skip update.") | ||
return | ||
self._last_cleaning_task = last_task | ||
self._image = self._device.get_cleaning_map( | ||
self._last_cleaning_task.cleaning_id | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DOMAIN = "dyson_cloud" | ||
|
||
CONF_REGION = "region" | ||
CONF_AUTH = "auth" | ||
|
||
DATA_ACCOUNT = "account" | ||
DATA_DEVICES = "devices" |
Oops, something went wrong.