Skip to content

Commit

Permalink
Add support vacuums
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Mar 26, 2021
1 parent b28e272 commit d27f30a
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ automation:
- **Розетки** - включая энергопотребление
- **Лампочки** - включая настройку яркости и цвета
- **Обогреватели**
- **Пылесосы**

В качестве ИК-пультов можно использовать Яндекс Пульт или более [дешевую версию от Tuya](https://www.aliexpress.com/item/32984694264.html) (добавляется напрямую как родной пульт Яндекса).

Expand Down
2 changes: 1 addition & 1 deletion custom_components/yandex_station/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async def _setup_include(hass: HomeAssistant, entry: ConfigEntry):
if CONF_INCLUDE not in config:
return

for domain in ('climate', 'light', 'remote', 'switch'):
for domain in ('climate', 'light', 'remote', 'switch', 'vacuum'):
hass.async_create_task(hass.config_entries.async_forward_entry_setup(
entry, domain
))
1 change: 1 addition & 0 deletions custom_components/yandex_station/core/yandex_quasar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'input_source': 'devices.capabilities.mode',
'brightness': 'devices.capabilities.range',
'color': 'devices.capabilities.color_setting',
'work_speed': 'devices.capabilities.mode',
# don't work
'hsv': 'devices.capabilities.color_setting',
'rgb': 'devices.capabilities.color_setting',
Expand Down
130 changes: 130 additions & 0 deletions custom_components/yandex_station/vacuum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import logging

from homeassistant.components.vacuum import StateVacuumEntity, SUPPORT_START, \
SUPPORT_STOP, SUPPORT_FAN_SPEED, SUPPORT_PAUSE, STATE_CLEANING, \
SUPPORT_BATTERY
from homeassistant.const import STATE_IDLE, STATE_PAUSED

from . import DOMAIN, CONF_INCLUDE, DATA_CONFIG, YandexQuasar

_LOGGER = logging.getLogger(__name__)

DEVICES = ['devices.types.vacuum_cleaner']


async def async_setup_entry(hass, entry, async_add_entities):
include = hass.data[DOMAIN][DATA_CONFIG][CONF_INCLUDE]
quasar = hass.data[DOMAIN][entry.unique_id]
devices = [
YandexVacuum(quasar, device)
for device in quasar.devices
if device['name'] in include and device['type'] in DEVICES
]
async_add_entities(devices)


# noinspection PyAbstractClass
class YandexVacuum(StateVacuumEntity):
_battery = None
_fan_speed = None
_fan_speed_list = None
_state = None
_supported = 0

def __init__(self, quasar: YandexQuasar, device: dict):
self.quasar = quasar
self.device = device

@property
def unique_id(self):
return self.device['id'].replace('-', '')

@property
def name(self):
return self.device['name']

@property
def should_poll(self):
return True

@property
def state(self):
return self._state

@property
def supported_features(self):
return self._supported

@property
def battery_level(self):
return self._battery

@property
def fan_speed(self):
return self._fan_speed

@property
def fan_speed_list(self):
return self._fan_speed_list

async def async_start(self):
await self.quasar.device_action(self.device['id'], on=True)

async def async_stop(self, **kwargs):
await self.quasar.device_action(self.device['id'], on=False)

async def async_pause(self):
await self.quasar.device_action(self.device['id'], pause=True)

async def async_set_fan_speed(self, fan_speed, **kwargs):
await self.quasar.device_action(self.device['id'],
work_speed=fan_speed)

async def async_added_to_hass(self):
data = await self.quasar.get_device(self.device['id'])

for capability in data['capabilities']:
# TODO: type devices.capabilities.on_off don't have property
# parameters instance
instance = capability['parameters'].get('instance', 'on')
if instance == 'on':
self._supported |= SUPPORT_START | SUPPORT_STOP

elif instance == 'work_speed':
self._supported |= SUPPORT_FAN_SPEED
self._fan_speed_list = [
p['value'] for p in capability['parameters']['modes']
]

elif instance == 'pause':
self._supported |= SUPPORT_PAUSE

for property_ in data['properties']:
instance = property_['parameters']['instance']
if instance == 'battery_level':
self._supported |= SUPPORT_BATTERY

await self.async_update(data)

async def async_update(self, data: dict = None):
if not data:
data = await self.quasar.get_device(self.device['id'])

for capability in data['capabilities']:
if not capability['retrievable']:
continue

instance = capability['state']['instance']
if instance == 'on':
self._state = (STATE_CLEANING if capability['state']['value']
else STATE_IDLE)
elif instance == 'work_speed':
self._fan_speed = capability['state']['value']
elif instance == 'pause':
if capability['state']['value']:
self._state = STATE_PAUSED

for property_ in data['properties']:
instance = property_['parameters']['instance']
if instance == 'battery_level':
self._battery = property_['state']['value']

0 comments on commit d27f30a

Please sign in to comment.