mirror of
https://github.com/Hypfer/Valetudo.git
synced 2025-10-26 11:27:27 +00:00
feat!: The sensor consumable type is now a subtype of the new type cleaning
This commit is contained in:
parent
b8477fbdb6
commit
b798ebb2de
@ -28,10 +28,10 @@ class ConsumableStateAttribute extends StateAttribute {
|
||||
ConsumableStateAttribute.TYPE = Object.freeze({
|
||||
FILTER: "filter",
|
||||
BRUSH: "brush",
|
||||
SENSOR: "sensor",
|
||||
MOP: "mop",
|
||||
DETERGENT: "detergent",
|
||||
BIN: "bin"
|
||||
BIN: "bin",
|
||||
CLEANING: "cleaning",
|
||||
});
|
||||
|
||||
/**
|
||||
@ -46,7 +46,8 @@ ConsumableStateAttribute.SUB_TYPE = Object.freeze({
|
||||
SECONDARY: "secondary",
|
||||
SIDE_LEFT: "side_left",
|
||||
SIDE_RIGHT: "side_right",
|
||||
DOCK: "dock"
|
||||
DOCK: "dock",
|
||||
SENSOR: "sensor"
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@ -197,7 +197,7 @@ class ConsumableMonitoringCapabilityMqttHandle extends CapabilityMqttHandle {
|
||||
const TYPE_MAPPING = Object.freeze({
|
||||
[stateAttrs.ConsumableStateAttribute.TYPE.BRUSH]: "Brush",
|
||||
[stateAttrs.ConsumableStateAttribute.TYPE.FILTER]: "Filter",
|
||||
[stateAttrs.ConsumableStateAttribute.TYPE.SENSOR]: "Sensor cleaning",
|
||||
[stateAttrs.ConsumableStateAttribute.TYPE.CLEANING]: "Cleaning",
|
||||
[stateAttrs.ConsumableStateAttribute.TYPE.MOP]: "Mop",
|
||||
[stateAttrs.ConsumableStateAttribute.TYPE.DETERGENT]: "Detergent",
|
||||
[stateAttrs.ConsumableStateAttribute.TYPE.BIN]: "Bin",
|
||||
@ -211,6 +211,7 @@ const SUBTYPE_MAPPING = Object.freeze({
|
||||
[stateAttrs.ConsumableStateAttribute.SUB_TYPE.ALL]: "",
|
||||
[stateAttrs.ConsumableStateAttribute.SUB_TYPE.NONE]: "",
|
||||
[stateAttrs.ConsumableStateAttribute.SUB_TYPE.DOCK]: "Dock",
|
||||
[stateAttrs.ConsumableStateAttribute.SUB_TYPE.SENSOR]: "Sensor",
|
||||
});
|
||||
|
||||
ConsumableMonitoringCapabilityMqttHandle.OPTIONAL = true;
|
||||
|
||||
@ -157,13 +157,14 @@ class DreameConsumableMonitoringCapability extends ConsumableMonitoringCapabilit
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ConsumableStateAttribute.TYPE.SENSOR:
|
||||
if (this.miot_actions.reset_sensor) {
|
||||
switch (subType) {
|
||||
case ConsumableStateAttribute.SUB_TYPE.ALL:
|
||||
case ConsumableStateAttribute.TYPE.CLEANING:
|
||||
switch (subType) {
|
||||
case ConsumableStateAttribute.SUB_TYPE.SENSOR:
|
||||
if (this.miot_actions.reset_sensor) {
|
||||
payload = this.miot_actions.reset_sensor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
case ConsumableStateAttribute.TYPE.MOP:
|
||||
@ -264,8 +265,8 @@ class DreameConsumableMonitoringCapability extends ConsumableMonitoringCapabilit
|
||||
) {
|
||||
if (msg.piid === this.miot_properties.sensor.piid) {
|
||||
consumable = new ConsumableStateAttribute({
|
||||
type: ConsumableStateAttribute.TYPE.SENSOR,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.ALL,
|
||||
type: ConsumableStateAttribute.TYPE.CLEANING,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.SENSOR,
|
||||
remaining: {
|
||||
value: Math.round(Math.max(0, msg.value * 60)),
|
||||
unit: ConsumableStateAttribute.UNITS.MINUTES
|
||||
@ -350,8 +351,8 @@ class DreameConsumableMonitoringCapability extends ConsumableMonitoringCapabilit
|
||||
if (this.miot_properties.sensor) {
|
||||
availableConsumables.push(
|
||||
{
|
||||
type: ConsumableStateAttribute.TYPE.SENSOR,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.ALL,
|
||||
type: ConsumableStateAttribute.TYPE.CLEANING,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.SENSOR,
|
||||
unit: ConsumableStateAttribute.UNITS.MINUTES,
|
||||
maxValue: 30 * 60
|
||||
}
|
||||
|
||||
@ -20,8 +20,8 @@ const MOCKED_CONSUMABLES = Object.freeze([
|
||||
serviceLife: 10,
|
||||
},
|
||||
{
|
||||
type: ConsumableStateAttribute.TYPE.SENSOR,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.ALL,
|
||||
type: ConsumableStateAttribute.TYPE.CLEANING,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.SENSOR,
|
||||
serviceLife: 5,
|
||||
},
|
||||
{
|
||||
@ -127,8 +127,8 @@ class MockConsumableMonitoringCapability extends ConsumableMonitoringCapability
|
||||
unit: ConsumableStateAttribute.UNITS.MINUTES
|
||||
},
|
||||
{
|
||||
type: ConsumableStateAttribute.TYPE.SENSOR,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.ALL,
|
||||
type: ConsumableStateAttribute.TYPE.CLEANING,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.SENSOR,
|
||||
unit: ConsumableStateAttribute.UNITS.MINUTES
|
||||
},
|
||||
{
|
||||
|
||||
@ -52,8 +52,8 @@ class RoborockConsumableMonitoringCapability extends ConsumableMonitoringCapabil
|
||||
}
|
||||
}),
|
||||
new ConsumableStateAttribute({
|
||||
type: ConsumableStateAttribute.TYPE.SENSOR,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.ALL,
|
||||
type: ConsumableStateAttribute.TYPE.CLEANING,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.SENSOR,
|
||||
remaining: {
|
||||
value: CONVERT_TO_MINUTES_REMAINING(data[0].sensor_dirty_time, 30),
|
||||
unit: ConsumableStateAttribute.UNITS.MINUTES
|
||||
@ -155,8 +155,8 @@ class RoborockConsumableMonitoringCapability extends ConsumableMonitoringCapabil
|
||||
maxValue: 150 * 60
|
||||
},
|
||||
{
|
||||
type: ConsumableStateAttribute.TYPE.SENSOR,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.ALL,
|
||||
type: ConsumableStateAttribute.TYPE.CLEANING,
|
||||
subType: ConsumableStateAttribute.SUB_TYPE.SENSOR,
|
||||
unit: ConsumableStateAttribute.UNITS.MINUTES,
|
||||
maxValue: 30 * 60
|
||||
}
|
||||
@ -220,8 +220,8 @@ const CONSUMABLE_TYPE_MAP = Object.freeze({
|
||||
[ConsumableStateAttribute.SUB_TYPE.MAIN]: "filter_work_time",
|
||||
[ConsumableStateAttribute.SUB_TYPE.DOCK]: "strainer_work_times"
|
||||
},
|
||||
[ConsumableStateAttribute.TYPE.SENSOR]: {
|
||||
[ConsumableStateAttribute.SUB_TYPE.ALL]: "sensor_dirty_time"
|
||||
[ConsumableStateAttribute.TYPE.CLEANING]: {
|
||||
[ConsumableStateAttribute.SUB_TYPE.SENSOR]: "sensor_dirty_time"
|
||||
},
|
||||
[ConsumableStateAttribute.TYPE.BIN]: {
|
||||
[ConsumableStateAttribute.SUB_TYPE.DOCK]: "dust_collection_work_times"
|
||||
|
||||
@ -54,8 +54,8 @@
|
||||
{
|
||||
"__class": "ConsumableStateAttribute",
|
||||
"metaData": {},
|
||||
"type": "sensor",
|
||||
"subType": "all",
|
||||
"type": "cleaning",
|
||||
"subType": "sensor",
|
||||
"remaining": {
|
||||
"value": 123,
|
||||
"unit": "minutes"
|
||||
|
||||
@ -166,8 +166,8 @@ export interface MapSegmentRenameRequestParameters {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type ConsumableType = "filter" | "brush" | "sensor" | "mop" | "detergent";
|
||||
export type ConsumableSubType = "none" | "all" | "main" | "secondary" | "side_left" | "side_right";
|
||||
export type ConsumableType = "filter" | "brush" | "mop" | "detergent" | "bin" | "cleaning" ;
|
||||
export type ConsumableSubType = "none" | "all" | "main" | "secondary" | "side_left" | "side_right" | "dock" | "sensor";
|
||||
export type ConsumableUnit = "minutes" | "percent";
|
||||
|
||||
export interface ConsumableState {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import React, {FunctionComponent} from "react";
|
||||
import {ValetudoEvent, ValetudoEventInteraction} from "../api";
|
||||
import {ConsumableSubType, ConsumableType, ValetudoEvent, ValetudoEventInteraction} from "../api";
|
||||
import {Button, ButtonGroup, Stack, styled, Typography} from "@mui/material";
|
||||
import {getConsumableName} from "../utils";
|
||||
import {formatRelative} from "date-fns";
|
||||
@ -47,7 +47,7 @@ const ConsumableDepletedEventControl: FunctionComponent<ValetudoEventRenderProps
|
||||
<Stack>
|
||||
<EventTimestamp timestamp={event.timestamp}/>
|
||||
<Typography color={color} style={textStyle} sx={{mr: 1}}>
|
||||
The consumable <em>{getConsumableName(event.type, event.subType)}</em> is depleted
|
||||
The consumable <em>{getConsumableName(event.type as ConsumableType, event.subType as ConsumableSubType)}</em> is depleted
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Button
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//Adapted from https://stackoverflow.com/a/34270811/10951033
|
||||
import {ValetudoDataPoint} from "./api";
|
||||
import {ConsumableSubType, ConsumableType, ValetudoDataPoint} from "./api";
|
||||
import {useCallback, useLayoutEffect, useRef} from "react";
|
||||
|
||||
export function convertSecondsToHumans(seconds: number, showSeconds = true, showDays = true): string {
|
||||
@ -126,26 +126,27 @@ export const deepCopy = <T>(target: T): T => {
|
||||
return target;
|
||||
};
|
||||
|
||||
const consumableTypeMapping: Record<string, string> = {
|
||||
const consumableTypeMapping: Record<ConsumableType, string> = {
|
||||
"brush": "Brush",
|
||||
"filter": "Filter",
|
||||
"sensor": "Sensor cleaning",
|
||||
"cleaning": "Cleaning",
|
||||
"mop": "Mop",
|
||||
"detergent": "Detergent",
|
||||
"bin": "Bin"
|
||||
};
|
||||
|
||||
const consumableSubtypeMapping: Record<string, string> = {
|
||||
const consumableSubtypeMapping: Record<ConsumableSubType, string> = {
|
||||
"main": "Main",
|
||||
"secondary": "Secondary",
|
||||
"side_right": "Right",
|
||||
"side_left": "Left",
|
||||
"all": "",
|
||||
"none": "",
|
||||
"dock": "Dock"
|
||||
"dock": "Dock",
|
||||
"sensor": "Sensor"
|
||||
};
|
||||
|
||||
export const getConsumableName = (type: string, subType?: string): string => {
|
||||
export const getConsumableName = (type: ConsumableType, subType?: ConsumableSubType): string => {
|
||||
let ret = "";
|
||||
if (subType && subType in consumableSubtypeMapping) {
|
||||
ret += consumableSubtypeMapping[subType] + " ";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user