Skip to content

Commit

Permalink
camera.py same as v1.1.7.beta
Browse files Browse the repository at this point in the history
connector.py same as v1.1.7.beta
image_handler.py same as v1.1.7.beta.
config_flow.py improved steps in the UI.
const.py added user defined generic colors.
colors.py added user defined generic colors.
test_config_flow.py changes for the new config_flow.py
test_camera.py changes for the new config_flow.py
Signed-off-by: SCA075 <[email protected]>

Signed-off-by: SCA075 <[email protected]>
  • Loading branch information
sca075 committed Jul 22, 2023
1 parent ee0380b commit 80b86d2
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 122 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ internal_variables:
```


### Current Release: v1.1.6
1) Dreame D9 Map Drawing, rooms, no go areas and paths are now correctly draw.
2) Resolves #6 issue in the Image Handler the image now load as it should.
3) We did separate the MQTT payload to have one payload dedicated only for the image processing.
4) Crop default is 50%. This would avoid HA instance to be over load with huge amount of data. Please use a crop factor <50 (example values between 20 and 40) when you want the image to be smaller (zoomed)
### Current Release: v1.1.7
1. Camera improvements:
- Automatic Standby: No image data will be process if the vacuum isn't working or moving. This free automatically resources to HA.
- If the vacuum is in Idle, Docked or Error the snapshot image (path to: "custom_components/valetudo_vacuum_camera/snapshots/valetudo_snapshot.png") is updated and ready to be used for the notification services of HA.
- The Frame Interval of the camera is now updated at each frame, this is helping to keep the image refresh more smooth and avoid over processing during the image updates.
2. Improved the logging, adding information's of what data have been received from MQTT.
3. Added the image_handler get_frame_number function. This function is for development purpose only. No influence on the image.
4. Improved user configuration via UI searching the vacuum entity id possible, as well the image rotation fixed values are minimizing inputs errors.
### In plan:
1) User interface could not be improved on V1.1.6 as per we did mainly work on the integration of the new vacuum. We set now as target v1.2.0.
2) Use the camera snapshot functions so that in case the battery of the vacuum is dead will be easy to locate it. It will be possible to send the last position of the vacuum setting up the notification in HA.
3) Improve the frames rate.
4) Adding to the configuration the colour setup for each element.
1) Some improved UI configuration steps on V1.1.7. We set now as target v1.2.0 to complete this.
2) Adding to the configuration the colour setup for each element is a work in progress as it is possible to see already on the new config_flow.
3) We will also add the capability to show segments names and active state on v1.2.0.

Note: Release of v1.1.8 will be postponed as per we will take a break next week :)

### How to install:
Using [HACS](https://hacs.xyz/) add integration, and copy the repository link in ***new repository*** section.
Expand Down
92 changes: 77 additions & 15 deletions custom_components/valetudo_vacuum_camera/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""Config Flow Version 1.1.5"""
"""config_flow ver.1.7.0"""

import voluptuous as vol
import logging
from typing import Any, Dict, Optional

from homeassistant import config_entries
from homeassistant.const import CONF_NAME
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.selector import (
EntitySelector,
ColorRGBSelector
)

from .const import (
DOMAIN,
Expand All @@ -16,46 +20,104 @@
DEFAULT_NAME,
ATT_ROTATE,
ATT_CROP,
COLOR_MOVE,
COLOR_ROBOT,
COLOR_WALL,
COLOR_CHARGER,
COLOR_BACKGROUND,
COLOR_GO_TO,
COLOR_NO_GO,
COLOR_ZONE_CLEAN
)

_LOGGER = logging.getLogger(__name__)

AUTH_SCHEMA = vol.Schema(
VACUUM_SCHEMA = vol.Schema(
{
vol.Required(CONF_VACUUM_ENTITY_ID): EntitySelector(),
}
)

MQTT_SCHEMA = vol.Schema(
{
vol.Required(CONF_VACUUM_ENTITY_ID): cv.string,
vol.Required(CONF_MQTT_USER): cv.string,
vol.Required(CONF_MQTT_PASS): cv.string,
vol.Required(CONF_VACUUM_CONNECTION_STRING): cv.string,
vol.Required(ATT_ROTATE, default="0"): cv.string,
}
)

IMG_SCHEMA = vol.Schema(
{
vol.Required(ATT_ROTATE, default="0"): vol.In(["0", "90", "180", "270"]),
vol.Required(ATT_CROP, default="50"): cv.string,
}
)

OPTIONS_SCHEMA = vol.Schema(
{vol.Optional(CONF_NAME, default="valetudo_vacuum_camera"): cv.entity_id}
GENERIC_COLOR_SCHEMA = vol.Schema(
{
vol.Optional(COLOR_BACKGROUND, default=[0, 125, 255]): ColorRGBSelector(),
vol.Optional(COLOR_ZONE_CLEAN, default=[255, 255, 255]): ColorRGBSelector(),
vol.Optional(COLOR_WALL, default=[255, 255, 0]): ColorRGBSelector(),
vol.Optional(COLOR_ROBOT, default=[255, 255, 204]): ColorRGBSelector(),
vol.Optional(COLOR_CHARGER, default=[255, 128, 0]): ColorRGBSelector(),
vol.Optional(COLOR_MOVE, default=[238, 247, 255]): ColorRGBSelector(),
vol.Optional(COLOR_GO_TO, default=[0, 255, 0]): ColorRGBSelector(),
vol.Optional(COLOR_NO_GO, default=[255, 0, 0]): ColorRGBSelector(),
}
)


class ValetudoCameraFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
def __init__(self):
self.data = None
VERSION = 1.1

async def async_step_user(self, user_input: Optional[Dict[str, Any]] = None):
if user_input is not None:
return await self.async_step_mqtt()

return self.async_show_form(step_id="user", data_schema=VACUUM_SCHEMA)

async def async_step_mqtt(self, user_input: Optional[Dict[str, Any]] = None):
if user_input is not None:
self.data = user_input
return await self.async_step_options_1()

return self.async_show_form(step_id="mqtt", data_schema=MQTT_SCHEMA)

async def async_step_options_1(self, user_input: Optional[Dict[str, Any]] = None):
if user_input is not None:
self.data.update(
{
"vacuum_entity": user_input.get(CONF_VACUUM_ENTITY_ID),
"broker_user": user_input.get(CONF_MQTT_USER),
"broker_password": user_input.get(CONF_MQTT_PASS),
"vacuum_map": user_input.get(CONF_VACUUM_CONNECTION_STRING),
"rotate_image": user_input.get(ATT_ROTATE),
"crop_image": user_input.get(ATT_CROP),
}
)

return await self.async_step_options_2()

return self.async_show_form(
step_id="options_1", data_schema=IMG_SCHEMA, description_placeholders=self.data
)

async def async_step_options_2(self, user_input: Optional[Dict[str, Any]] = None):
if user_input is not None:
self.data.update(
{
"color_charger": user_input.get(COLOR_CHARGER),
"color_move": user_input.get(COLOR_MOVE),
"color_wall": user_input.get(COLOR_WALL),
"color_robot": user_input.get(COLOR_ROBOT),
"color_go_to": user_input.get(COLOR_GO_TO),
"color_no_go": user_input.get(COLOR_NO_GO),
"color_zone_clean": user_input.get(COLOR_ZONE_CLEAN),
"color_background": user_input.get(COLOR_BACKGROUND),
}
)

return self.async_create_entry(
title=DEFAULT_NAME,
data=user_input,
data=self.data,
)

return self.async_show_form(step_id="user", data_schema=AUTH_SCHEMA)
return self.async_show_form(
step_id="options_2", data_schema=GENERIC_COLOR_SCHEMA, description_placeholders=self.data
)
11 changes: 10 additions & 1 deletion custom_components/valetudo_vacuum_camera/const.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Constants for the valetudo_vacuum_camera integration."""
"""Version 1.1.5"""
"""Version 1.1.7"""

"""Required in Config_Flow"""
PLATFORMS = ["camera"]
Expand All @@ -17,3 +17,12 @@
"""App Constants"""
IDLE_SCAN_INTERVAL = 120
CLEANING_SCAN_INTERVAL = 5

COLOR_CHARGER = "color_charger"
COLOR_MOVE = "color_move"
COLOR_ROBOT = "color_robot"
COLOR_NO_GO = "color_no_go"
COLOR_GO_TO = "color_go_to"
COLOR_BACKGROUND = "color_background"
COLOR_ZONE_CLEAN = "color_zone_clean"
COLOR_WALL = "color_wall"
56 changes: 48 additions & 8 deletions custom_components/valetudo_vacuum_camera/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,63 @@
"step": {
"user": {
"data": {
"vacuum_entity": "Vacuum Entity ID",
"vacuum_entity": "Vacuum Entity ID"
},
"data_description": {
"vacuum_entity": "Vacuum Entity ID"
},
"description": "Camera Setup.",
"title": "Valetudo Camera Setup"
},
"mqtt": {
"data": {
"broker_user": "MQTT User Name",
"broker_password": "MQTT User Password",
"vacuum_map": "Vacuum Topic Prefix/Identifier",
"rotate_image": "0",
"crop_image": "50"
"vacuum_map": "Vacuum Topic Prefix/Identifier"
},
"data_description": {
"vacuum_entity": "Vacuum Entity ID",
"broker_user": "MQTT User Name",
"broker_password": "MQTT User Password",
"vacuum_map": "Vacuum Topic Prefix/Identifier",
"vacuum_map": "Vacuum Topic Prefix/Identifier"
},
"description": "MQTT Configuration.",
"title": "MQTT Configuration"
},
"options_1": {
"data": {
"rotate_image": "Rotate",
"crop_image": "50"
},
"data_description": {
"rotate_image": "Degree 0, 90, 180, 270",
"crop_image": "Crop the image in %"
},
"description": "Camera Setup.",
"title": "Valetudo Camera Setup"
"description": "Camera Options. Part 1/3",
"title": "Camera Options"
},
"options_2": {
"data": {
"color_charger": "[255, 128, 0]",
"color_move": "[238, 247, 255]",
"color_wall": "[255, 255, 0]",
"color_robot": "[255, 255, 204]",
"color_go_to": "[0, 255, 0]",
"color_no_go": "[255, 0, 0]",
"color_zone_clean": "[255, 255, 255]",
"color_background": "[0, 125, 255]"
},
"data_description": {
"color_charger": "Charger color",
"color_move": "Move color",
"color_wall": "Wall color",
"color_robot": "Robot color",
"color_go_to": "Go-to color",
"color_no_go": "No-go color",
"color_zone_clean": "Zone clean color",
"color_background": "Background color"
},
"description": "Camera Options. Part 2/3",
"title": "Camera Options"
}
},
"abort": {
Expand Down
56 changes: 48 additions & 8 deletions custom_components/valetudo_vacuum_camera/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,63 @@
"step": {
"user": {
"data": {
"vacuum_entity": "Vacuum Entity ID",
"vacuum_entity": "Vacuum Entity ID"
},
"data_description": {
"vacuum_entity": "Vacuum Entity ID"
},
"description": "Camera Setup.",
"title": "Valetudo Camera Setup"
},
"mqtt": {
"data": {
"broker_user": "MQTT User Name",
"broker_password": "MQTT User Password",
"vacuum_map": "Vacuum Topic Prefix/Identifier",
"rotate_image": "0",
"crop_image": "50"
"vacuum_map": "Vacuum Topic Prefix/Identifier"
},
"data_description": {
"vacuum_entity": "Vacuum Entity ID",
"broker_user": "MQTT User Name",
"broker_password": "MQTT User Password",
"vacuum_map": "Vacuum Topic Prefix/Identifier",
"vacuum_map": "Vacuum Topic Prefix/Identifier"
},
"description": "MQTT Configuration.",
"title": "MQTT Configuration"
},
"options_1": {
"data": {
"rotate_image": "Rotate",
"crop_image": "50"
},
"data_description": {
"rotate_image": "Degree 0, 90, 180, 270",
"crop_image": "Crop the image in %"
},
"description": "Camera Setup.",
"title": "Valetudo Camera Setup"
"description": "Camera Options. Part 1/3",
"title": "Camera Options"
},
"options_2": {
"data": {
"color_charger": "[255, 128, 0]",
"color_move": "[238, 247, 255]",
"color_wall": "[255, 255, 0]",
"color_robot": "[255, 255, 204]",
"color_go_to": "[0, 255, 0]",
"color_no_go": "[255, 0, 0]",
"color_zone_clean": "[255, 255, 255]",
"color_background": "[0, 125, 255]"
},
"data_description": {
"color_charger": "Charger color",
"color_move": "Move color",
"color_wall": "Wall color",
"color_robot": "Robot color",
"color_go_to": "Go-to color",
"color_no_go": "No-go color",
"color_zone_clean": "Zone clean color",
"color_background": "Background color"
},
"description": "Camera Options. Part 2/3",
"title": "Camera Options"
}
},
"abort": {
Expand Down
38 changes: 35 additions & 3 deletions custom_components/valetudo_vacuum_camera/utils/colors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
"""Colors RGBA"""
"""Version 1.1.6beta"""
"""Version 1.1.7"""

from custom_components.valetudo_vacuum_camera.const import (
COLOR_ROBOT,
COLOR_BACKGROUND,
COLOR_WALL,
COLOR_MOVE,
COLOR_CHARGER,
COLOR_NO_GO,
COLOR_GO_TO,
COLOR_ZONE_CLEAN
)

import logging

_LOGGER = logging.getLogger(__name__)

color_transparent = (0, 0, 0, 0)
color_charger = (0, 128, 0, 255)
color_move = (238, 247, 255, 255) # (192, 192, 192, 255)
color_move = (238, 247, 255, 255)
color_robot = (255, 255, 204, 255)
color_no_go = (255, 0, 0, 255)
color_go_to = (0, 255, 0, 255)
Expand All @@ -30,7 +45,6 @@
color_room_14 = (72, 201, 176, 255)
color_room_15 = (165, 105, 18, 255)


rooms_color = [
color_room_0,
color_room_1,
Expand All @@ -49,6 +63,7 @@
color_room_14,
color_room_15,
]

color_array = [
color_wall,
color_no_go,
Expand All @@ -63,3 +78,20 @@
color_transparent,
rooms_color,
]

user_color_array = [
COLOR_WALL,
COLOR_NO_GO,
COLOR_GO_TO,
color_black,
COLOR_ROBOT,
COLOR_CHARGER,
color_white,
COLOR_MOVE,
COLOR_BACKGROUND,
COLOR_ZONE_CLEAN,
color_transparent,
rooms_color,
]

_LOGGER.info("Colors in user_color_array: %s", user_color_array)
Loading

0 comments on commit 80b86d2

Please sign in to comment.