Skip to content

Commit 5b39eb7

Browse files
authored
Merge pull request #21 from nergal/develop
Add platform configuration
2 parents 57a43b8 + 69de49d commit 5b39eb7

19 files changed

+690
-130
lines changed

.github/workflows/workflow.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ jobs:
3030
- name: Run lint checks
3131
run: make lint
3232
- name: Run unit tests
33-
run: make test
33+
run: make coverage
34+
- name: Upload Coverage to Codecov
35+
uses: codecov/codecov-action@v1
3436

3537
analyze:
3638
name: Analyze CodeQL

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
.vscode/
44
__pycache__/
55
.idea/
6+
.coverage
7+
.DS_Store
68
*.tmp
79
*.log

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ test:
2626
$(POETRY) run pytest $(TEST_FOLDER)
2727

2828
coverage:
29-
$(POETRY) run pytest --cov-report term $(TEST_FOLDER)
29+
$(POETRY) run pytest --cov-report xml --cov=custom_components.xiaomi_viomi $(TEST_FOLDER)

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Homeassistant Vacuum Viomi integration for HACS
22

33
[![hacs_badge](https://img.shields.io/badge/HACS-Custom-orange.svg)](https://github.com/custom-components/hacs)
4+
[![codecov](https://codecov.io/gh/nergal/homeassistant-vacuum-viomi/branch/master/graph/badge.svg?token=MUHLPCJY2G)](https://codecov.io/gh/nergal/homeassistant-vacuum-viomi)
45
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
56
![GitHub](https://img.shields.io/github/license/nergal/homeassistant-vacuum-viomi)
67
[![Validation flow](https://github.com/nergal/homeassistant-vacuum-viomi/actions/workflows/workflow.yaml/badge.svg)](https://github.com/nergal/homeassistant-vacuum-viomi/actions/workflows/workflow.yaml)
@@ -14,7 +15,18 @@ Xiaomi Viomi vacuum robot integration for Home Assistant.
1415
### HACS
1516
Install it through HACS by adding this as a custom repository: https://github.com/nergal/homeassistant-vacuum-viomi, go to the integrations page in your configuration, click on the `Add Integration` button in the bottom right corner of a screen, and search for `Xiaomi Viomi Vacuum`.
1617

17-
Manual installation currently not supported.
18+
### Manual
19+
Copy contents of `custom_components` folder to your Home Assistant `config/custom_components` folder. Restart Home Assistant, and then the integration can be added and configured through the native integration setup. If you don't see it in the native integrations list, press Ctrl+F5 to refresh the browser while you're on that page and retry.
20+
21+
Also you may add the manual configuration to `configuration.yaml` file, like the example below:
22+
23+
```
24+
vacuum:
25+
- platform: xiaomi_viomi
26+
host: 192.168.1.1
27+
token: !secret vacuum
28+
name: Vacuum V8
29+
```
1830

1931
## Tested models
2032
| Model | Device ID | Aliases | Status |

codecov.yml

Whitespace-only changes.

custom_components/xiaomi_viomi/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
"""Xiaomi Viomi integration."""
22
import asyncio
33

4+
import voluptuous as vol
5+
from homeassistant.components.vacuum import PLATFORM_SCHEMA
46
from homeassistant.config_entries import ConfigEntry
7+
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_TOKEN, DEVICE_DEFAULT_NAME
58
from homeassistant.core import HomeAssistant
9+
from homeassistant.helpers import config_validation as cv
10+
11+
from .const import DOMAIN # noqa: F401
612

713
PLATFORMS = ["vacuum"]
814

15+
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
16+
{
17+
vol.Optional(CONF_NAME, default=DEVICE_DEFAULT_NAME): cv.string,
18+
vol.Required(CONF_TOKEN): cv.string,
19+
vol.Required(CONF_HOST): cv.string,
20+
}
21+
)
22+
923

1024
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
1125
"""Set up Xiaomi Viomi from a config entry."""

custom_components/xiaomi_viomi/config_flow.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
import voluptuous as vol
66
from construct.core import ChecksumError
77
from homeassistant import config_entries
8-
from homeassistant.const import CONF_HOST, CONF_TOKEN
8+
from homeassistant.components.xiaomi_miio import CONF_MODEL
9+
from homeassistant.const import (
10+
CONF_HOST,
11+
CONF_MAC,
12+
CONF_NAME,
13+
CONF_PLATFORM,
14+
CONF_TOKEN,
15+
DEVICE_DEFAULT_NAME,
16+
)
917
from homeassistant.core import HomeAssistant
1018
from homeassistant.data_entry_flow import FlowResult
1119
from homeassistant.exceptions import ConfigEntryAuthFailed, HomeAssistantError
@@ -14,14 +22,15 @@
1422
from miio.device import DeviceInfo
1523
from miio.integrations.vacuum.viomi.viomivacuum import ViomiVacuum
1624

17-
from .const import CONF_MAC, CONF_MODEL, DOMAIN
25+
from .const import DOMAIN
1826

1927
_LOGGER = logging.getLogger(__name__)
2028

2129
DEVICE_CONFIG = vol.Schema(
2230
{
2331
vol.Required(CONF_HOST): str,
2432
vol.Required(CONF_TOKEN): vol.All(str, vol.Length(min=32, max=32)),
33+
vol.Optional(CONF_NAME, default=DEVICE_DEFAULT_NAME): str,
2534
}
2635
)
2736

@@ -76,10 +85,15 @@ async def validate_input(hass: HomeAssistant, data: Dict[str, Any]) -> Dict[str,
7685
if not await hub.async_device_is_connectable(data[CONF_HOST], data[CONF_TOKEN]):
7786
raise InvalidAuth
7887

88+
DEVICE_CONFIG.extend({vol.Optional(CONF_PLATFORM): str})(data)
89+
90+
name = data[CONF_NAME] if CONF_NAME in data else hub.device_info.model
91+
7992
return {
8093
CONF_HOST: data[CONF_HOST],
8194
CONF_TOKEN: data[CONF_TOKEN],
8295
CONF_MODEL: hub.device_info.model,
96+
CONF_NAME: name,
8397
CONF_MAC: format_mac(hub.device_info.mac_address),
8498
}
8599

@@ -116,12 +130,13 @@ async def async_step_user(
116130
data = existing_entry.data.copy()
117131
data[CONF_HOST] = info[CONF_HOST]
118132
data[CONF_TOKEN] = info[CONF_TOKEN]
133+
data[CONF_NAME] = info[CONF_NAME]
119134

120135
self.hass.config_entries.async_update_entry(existing_entry, data=data)
121136
await self.hass.config_entries.async_reload(existing_entry.entry_id)
122137
return self.async_abort(reason="already_configured")
123138

124-
return self.async_create_entry(title=info[CONF_MODEL], data=info)
139+
return self.async_create_entry(title=info[CONF_NAME], data=info)
125140

126141
return self.async_show_form(
127142
step_id="user", data_schema=DEVICE_CONFIG, errors=errors

custom_components/xiaomi_viomi/const.py

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
"""Constants for Xiaomi Viomi integration."""
22

3+
from homeassistant.components.vacuum import (
4+
STATE_CLEANING,
5+
STATE_DOCKED,
6+
STATE_IDLE,
7+
STATE_RETURNING,
8+
SUPPORT_BATTERY,
9+
SUPPORT_FAN_SPEED,
10+
SUPPORT_LOCATE,
11+
SUPPORT_PAUSE,
12+
SUPPORT_RETURN_HOME,
13+
SUPPORT_SEND_COMMAND,
14+
SUPPORT_START,
15+
SUPPORT_STATE,
16+
SUPPORT_STOP,
17+
)
18+
319
DOMAIN = "xiaomi_viomi"
4-
CONF_DEVICE = "device"
5-
CONF_MODEL = "model"
6-
CONF_MAC = "mac"
720
CONF_FLOW_TYPE = "config_flow_device"
821

9-
MODELS_VACUUM = ["viomi.vacuum.v8"]
10-
1122
DEVICE_PROPERTIES = [
1223
"battary_life",
1324
"box_type",
@@ -46,3 +57,45 @@
4657
"hypa_hours",
4758
"hypa_life",
4859
]
60+
61+
ATTR_CLEANING_TIME = "cleaning_time"
62+
ATTR_DO_NOT_DISTURB = "do_not_disturb"
63+
ATTR_DO_NOT_DISTURB_START = "do_not_disturb_start"
64+
ATTR_DO_NOT_DISTURB_END = "do_not_disturb_end"
65+
ATTR_MAIN_BRUSH_LEFT = "main_brush_left"
66+
ATTR_SIDE_BRUSH_LEFT = "side_brush_left"
67+
ATTR_FILTER_LEFT = "filter_left"
68+
ATTR_MOP_LEFT = "mop_left"
69+
ATTR_ERROR = "error"
70+
ATTR_STATUS = "status"
71+
ATTR_MOP_ATTACHED = "mop_attached"
72+
73+
ERRORS_FALSE_POSITIVE = (
74+
0, # Sleeping and not charging,
75+
2103, # Charging
76+
2104, # ? Returning
77+
2105, # Fully charged
78+
2110, # ? Cleaning
79+
)
80+
81+
SUPPORT_VIOMI = (
82+
SUPPORT_PAUSE
83+
| SUPPORT_STOP
84+
| SUPPORT_RETURN_HOME
85+
| SUPPORT_FAN_SPEED
86+
| SUPPORT_BATTERY
87+
| SUPPORT_SEND_COMMAND
88+
| SUPPORT_LOCATE
89+
| SUPPORT_STATE
90+
| SUPPORT_START
91+
)
92+
93+
STATE_CODE_TO_STATE = {
94+
0: STATE_IDLE, # IdleNotDocked
95+
1: STATE_IDLE, # Idle
96+
2: STATE_IDLE, # Idle2
97+
3: STATE_CLEANING, # Cleaning
98+
4: STATE_RETURNING, # Returning
99+
5: STATE_DOCKED, # Docked
100+
6: STATE_CLEANING, # VacuumingAndMopping
101+
}

custom_components/xiaomi_viomi/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"construct==2.10.67",
1212
"python-miio==0.5.9"
1313
],
14-
"version": "0.0.3"
14+
"version": "0.0.4"
1515
}

custom_components/xiaomi_viomi/strings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"error": {
44
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
55
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
6+
"invalid_parameters": "[%key:common::config_flow::error::invalid_auth%]",
67
"unknown": "[%key:common::config_flow::error::unknown%]"
78
},
89
"abort": {
@@ -13,10 +14,11 @@
1314
"user": {
1415
"data": {
1516
"host": "[%key:common::config_flow::data::host%]",
16-
"token": "[%key:common::config_flow::data::api_token%]"
17+
"token": "[%key:common::config_flow::data::api_token%]",
18+
"name": "[%key:common::config_flow::data::name%]"
1719
},
1820
"description": "You will need the 32 character [%key:common::config_flow::data::api_token%], see https://www.home-assistant.io/integrations/xiaomi_miio#retrieving-the-access-token for instructions. Please note, that this [%key:common::config_flow::data::api_token%] is different from the key used by the Xiaomi Aqara integration.",
19-
"title": "Connect to a Xiaomi Viomi Device2"
21+
"title": "Connect to a Xiaomi Viomi Device"
2022
}
2123
}
2224
}

custom_components/xiaomi_viomi/translations/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
"error": {
77
"invalid_auth": "Incomplete information to setup device, no host or token supplied",
88
"cannot_connect": "Failed to connect",
9+
"invalid_parameters": "Invalid parameters were provided",
910
"unknown": "Unknown error occurred"
1011
},
1112
"flow_title": "{name}",
1213
"step": {
1314
"user": {
1415
"data": {
1516
"host": "IP Address",
16-
"token": "API Token"
17+
"token": "API Token",
18+
"name": "Name of a device"
1719
},
1820
"description": "You will need the 32 character API Token, see https://www.home-assistant.io/integrations/xiaomi_miio#retrieving-the-access-token for instructions. Please note, that this API Token is different from the key used by the Xiaomi Aqara integration.",
1921
"title": "Connect to a Xiaomi Viomi Device"

custom_components/xiaomi_viomi/translations/ru.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"error": {
44
"invalid_auth": "Неполная информация для настройки устройства, не указан хост или токен",
55
"cannot_connect": "Не удалось подключиться",
6+
"invalid_parameters": "Предоставлены неверные параметры устройства",
67
"unknown": "Произошла неизвесная ошибка"
78
},
89
"abort": {
@@ -13,7 +14,8 @@
1314
"user": {
1415
"data": {
1516
"host": "IP-адрес",
16-
"token": "Токен API"
17+
"token": "Токен API",
18+
"name": "Имя устройства"
1719
},
1820
"description": "Для подключения требуется 32-х значный Токен API. О том, как получить токен, Вы можете узнать здесь:\nhttps://www.home-assistant.io/integrations/xiaomi_miio#retrieving-the-access-token.\nОбратите внимание, что этот токен отличается от ключа, используемого при интеграции Xiaomi Aqara.",
1921
"title": "Подключение к устройству Xiaomi Viomi"

custom_components/xiaomi_viomi/translations/uk.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"error": {
44
"invalid_auth": "Неповна інформація для налагодження пристрою, не зазначений хост чи токен",
55
"cannot_connect": "Не вдалося під'єднатися",
6+
"invalid_parameters": "Надані невірні параметри пристрою",
67
"unknown": "Трапилась невідома помилка"
78
},
89
"abort": {
@@ -13,7 +14,8 @@
1314
"user": {
1415
"data": {
1516
"host": "IP-адреса",
16-
"token": "Токен API"
17+
"token": "Токен API",
18+
"name": "Ім'я пристрою"
1719
},
1820
"description": "Для підключення потрібно 32-х значний Токен API. Про те, як отримати токен, Ви можете дізнатися тут:\nhttps://www.home-assistant.io/integrations/vacuum.xiaomi_miio/#retrieving-the-access-token.\nЗверніть увагу, що цей токен відрізняється від ключа, який використовується при інтеграції Xiaomi Aqara.",
1921
"title": "Підключення до пристрою Xiaomi Viomi"

0 commit comments

Comments
 (0)