From 7d53fd5f5494e548975709c349ed9211a5a223f9 Mon Sep 17 00:00:00 2001 From: Arne Zellentin Date: Thu, 16 Sep 2021 19:46:12 +0200 Subject: [PATCH] feat: add message and extended_status state attributes They replace the status_type, status_code and attention_request_code state attributes. Textual representation is used if available. --- custom_components/badconga/app/client.py | 2 +- custom_components/badconga/app/const.py | 20 ++++++++++++ custom_components/badconga/app/entities.py | 2 +- custom_components/badconga/vacuum.py | 36 +++++++++++++++++++--- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/custom_components/badconga/app/client.py b/custom_components/badconga/app/client.py index 1d8bfa9..65f5e83 100644 --- a/custom_components/badconga/app/client.py +++ b/custom_components/badconga/app/client.py @@ -140,7 +140,7 @@ def handle_device_list(self, schema): def handle_device_busy(self, schema): """ handle_device_busy """ - self.device.attention_request_code = schema.result + self.device.busy_result = schema.result def handle_user_kick(self, schema): """ handle_user_kick """ diff --git a/custom_components/badconga/app/const.py b/custom_components/badconga/app/const.py index ac9f72a..554f945 100644 --- a/custom_components/badconga/app/const.py +++ b/custom_components/badconga/app/const.py @@ -130,3 +130,23 @@ MODEL_NAME = { MODEL_TYPE_CONGA_5090: 'Conga 5090' } + +STATUS_TYPES = { + 1: "Error", + 2: "Attention", + 3: "Information", +} + +STATUS_CODES = { + 501: "Wheels stuck or suspended", + 2102: "Cleaning finished, returning to dock", + 2103: "Charging", + 2104: "Cleaning aborted, returning to dock", + 2105: "Fully charged", + #2108: "unknown", + 2110: "Orienting", +} + +BUSY_CODES = { + 2: "New map", +} diff --git a/custom_components/badconga/app/entities.py b/custom_components/badconga/app/entities.py index 3af60ea..016bc24 100644 --- a/custom_components/badconga/app/entities.py +++ b/custom_components/badconga/app/entities.py @@ -52,9 +52,9 @@ def __init__(self): self.charge_status = False self.clean_time = None self.clean_size = None - self.attention_request_code = False self.type = 0 self.fault_code = None + self.busy_result = False self.fan_mode: FanMode = FAN_MODE_UNKNOWN self.serial_number = None self.utc_registered = None diff --git a/custom_components/badconga/vacuum.py b/custom_components/badconga/vacuum.py index b676901..491dc02 100644 --- a/custom_components/badconga/vacuum.py +++ b/custom_components/badconga/vacuum.py @@ -2,6 +2,7 @@ # pylint: disable=unused-argument import logging from functools import partial + from homeassistant.components.vacuum import ( VacuumEntity, SUPPORT_START, @@ -14,7 +15,17 @@ SUPPORT_LOCATE, SUPPORT_MAP ) -from .app.const import FAN_MODE_NONE, FAN_MODE_ECO, FAN_MODE_NORMAL, FAN_MODE_TURBO, MODEL_NAME + +from .app.const import ( + FAN_MODE_NONE, + FAN_MODE_ECO, + FAN_MODE_NORMAL, + FAN_MODE_TURBO, + MODEL_NAME, + STATUS_CODES, + BUSY_CODES +) + from .app.conga import Conga from . import DOMAIN @@ -47,7 +58,7 @@ def unique_id(self): serial = self.instance.client.device.serial_number if serial is None: return None - return f"{serial}-vacuum" + return f'{serial}-vacuum' @property def state(self): @@ -61,11 +72,26 @@ def status(self): @property def state_attributes(self): + extended_status = None + ftype = self.instance.client.device.type + fcode = self.instance.client.device.fault_code + if ftype and fcode: + extended_status = ( + STATUS_CODES[fcode] if fcode in STATUS_CODES + else f'unknown ({fcode})' + ) + + message = None + code = self.instance.client.device.busy_result + if code: + message = ( + BUSY_CODES[code] if code in BUSY_CODES else f'unknown ({code})' + ) + data = super().state_attributes data['clean_mode'] = self.instance.client.device.clean_mode - data['attention_request_code'] = self.instance.client.device.attention_request_code - data['fault_type'] = self.instance.client.device.type - data['fault_code'] = self.instance.client.device.fault_code + data['extended_status'] = extended_status + data['message'] = message data['robot_x'] = self.instance.client.map.robot.x data['robot_y'] = self.instance.client.map.robot.y data['robot_phi'] = self.instance.client.map.robot.phi