Skip to content

Commit

Permalink
feat: Provide list of attachments supported by the model of robot
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Mar 3, 2022
1 parent f27bbfd commit fe65df3
Show file tree
Hide file tree
Showing 22 changed files with 344 additions and 266 deletions.
13 changes: 12 additions & 1 deletion backend/lib/core/ValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,22 @@ class ValetudoRobot {
return "ValetudoRobot";
}

/**
* This method may be overridden to return model-specific details
* such as which types of attachments to expect in the state
*
* @returns {object}
*/
getModelDetails() {
return {
supportedAttachments: []
};
}

/**
* This method may be overridden to return robot-specific well-known properties
* such as the firmware version
*
* @abstract
* @returns {object}
*/
getProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"dustbin",
"watertank",
"mop"
]
"$ref": "#/components/schemas/AttachmentStateAttributeType"
},
"attached": {
"type": "boolean"
}
}
}
]
},
"AttachmentStateAttributeType": {
"type": "string",
"enum": [
"dustbin",
"watertank",
"mop"
]
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions backend/lib/robots/dreame/DreameValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ class DreameValetudoRobot extends MiioValetudoRobot {
return firmwareVersion;
}

getModelDetails() {
return {
supportedAttachments: [
stateAttrs.AttachmentStateAttribute.TYPE.WATERTANK,
stateAttrs.AttachmentStateAttribute.TYPE.MOP,
]
};
}

/**
* @return {object}
*/
Expand Down
2 changes: 1 addition & 1 deletion backend/lib/robots/roborock/RoborockGen4ValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class RoborockGen4ValetudoRobot extends RoborockValetudoRobot {
* @param {object} options
* @param {import("../../Configuration")} options.config
* @param {import("../../ValetudoEventStore")} options.valetudoEventStore
* @param {Array<import("../../entities/state/attributes/AttachmentStateAttribute").AttachmentStateAttributeType>} [options.attachmentTypes]
* @param {Array<import("../../entities/state/attributes/AttachmentStateAttribute").AttachmentStateAttributeType>} [options.supportedAttachments]
*/
constructor(options) {
super(Object.assign({}, options, {fanSpeeds: FAN_SPEEDS}));
Expand Down
4 changes: 2 additions & 2 deletions backend/lib/robots/roborock/RoborockS5MaxValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RoborockS5MaxValetudoRobot extends RoborockValetudoRobot {
{
fanSpeeds: FAN_SPEEDS,
waterGrades: WATER_GRADES,
attachmentTypes: ATTACHMENT_TYPES
supportedAttachments: SUPPORTED_ATTACHMENTS
}
)
);
Expand Down Expand Up @@ -93,7 +93,7 @@ const WATER_GRADES = {
[entities.state.attributes.PresetSelectionStateAttribute.INTENSITY.HIGH]: 203
};

const ATTACHMENT_TYPES = [
const SUPPORTED_ATTACHMENTS = [
entities.state.attributes.AttachmentStateAttribute.TYPE.WATERTANK,
entities.state.attributes.AttachmentStateAttribute.TYPE.MOP,
];
Expand Down
4 changes: 2 additions & 2 deletions backend/lib/robots/roborock/RoborockS6MaxVValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RoborockS6MaxVValetudoRobot extends RoborockValetudoRobot {
{
fanSpeeds: FAN_SPEEDS,
waterGrades: WATER_GRADES,
attachmentTypes: ATTACHMENT_TYPES
supportedAttachments: SUPPORTED_ATTACHMENTS
}
)
);
Expand Down Expand Up @@ -94,7 +94,7 @@ const WATER_GRADES = {
[entities.state.attributes.PresetSelectionStateAttribute.INTENSITY.HIGH]: 203
};

const ATTACHMENT_TYPES = [
const SUPPORTED_ATTACHMENTS = [
entities.state.attributes.AttachmentStateAttribute.TYPE.WATERTANK,
entities.state.attributes.AttachmentStateAttribute.TYPE.MOP,
];
Expand Down
4 changes: 2 additions & 2 deletions backend/lib/robots/roborock/RoborockS7ValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RoborockS7ValetudoRobot extends RoborockGen4ValetudoRobot {
options,
{
waterGrades: WATER_GRADES,
attachmentTypes: ATTACHMENT_TYPES
supportedAttachments: SUPPORTED_ATTACHMENTS
}
)
);
Expand Down Expand Up @@ -78,7 +78,7 @@ const WATER_GRADES = {
[entities.state.attributes.PresetSelectionStateAttribute.INTENSITY.HIGH]: 203
};

const ATTACHMENT_TYPES = [
const SUPPORTED_ATTACHMENTS = [
entities.state.attributes.AttachmentStateAttribute.TYPE.WATERTANK,
entities.state.attributes.AttachmentStateAttribute.TYPE.MOP,
];
Expand Down
16 changes: 11 additions & 5 deletions backend/lib/robots/roborock/RoborockValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ class RoborockValetudoRobot extends MiioValetudoRobot {
* @param {import("../../ValetudoEventStore")} options.valetudoEventStore
* @param {object} options.fanSpeeds
* @param {object} [options.waterGrades]
* @param {Array<import("../../entities/state/attributes/AttachmentStateAttribute").AttachmentStateAttributeType>} [options.attachmentTypes]
* @param {Array<import("../../entities/state/attributes/AttachmentStateAttribute").AttachmentStateAttributeType>} [options.supportedAttachments]
*/
constructor(options) {
super(options);

this.lastMapPoll = new Date(0);
this.fanSpeeds = options.fanSpeeds;
this.waterGrades = options.waterGrades ?? {};
this.attachmentTypes = options.attachmentTypes ?? [];
this.supportedAttachments = options.supportedAttachments ?? [];

this.attachmentTypes.forEach(attachmentType => {
this.supportedAttachments.forEach(attachmentType => {
this.state.upsertFirstMatchingAttribute(new entities.state.attributes.AttachmentStateAttribute({
type: attachmentType,
attached: false
Expand Down Expand Up @@ -281,7 +281,7 @@ class RoborockValetudoRobot extends MiioValetudoRobot {

if (
data["water_box_status"] !== undefined &&
this.attachmentTypes.includes(stateAttrs.AttachmentStateAttribute.TYPE.WATERTANK)
this.supportedAttachments.includes(stateAttrs.AttachmentStateAttribute.TYPE.WATERTANK)
) {
this.state.upsertFirstMatchingAttribute(new stateAttrs.AttachmentStateAttribute({
type: stateAttrs.AttachmentStateAttribute.TYPE.WATERTANK,
Expand All @@ -291,7 +291,7 @@ class RoborockValetudoRobot extends MiioValetudoRobot {

if (
data["water_box_carriage_status"] !== undefined &&
this.attachmentTypes.includes(stateAttrs.AttachmentStateAttribute.TYPE.MOP)
this.supportedAttachments.includes(stateAttrs.AttachmentStateAttribute.TYPE.MOP)
) {
this.state.upsertFirstMatchingAttribute(new stateAttrs.AttachmentStateAttribute({
type: stateAttrs.AttachmentStateAttribute.TYPE.MOP,
Expand Down Expand Up @@ -492,6 +492,12 @@ class RoborockValetudoRobot extends MiioValetudoRobot {
}
}

getModelDetails() {
return {
supportedAttachments: this.supportedAttachments
};
}

/**
* @return {object}
*/
Expand Down
10 changes: 10 additions & 0 deletions backend/lib/robots/viomi/ViomiValetudoRobot.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,16 @@ class ViomiValetudoRobot extends MiioValetudoRobot {
getManufacturer() {
return "Viomi";
}

getModelDetails() {
return {
supportedAttachments: [
stateAttrs.AttachmentStateAttribute.TYPE.DUSTBIN,
stateAttrs.AttachmentStateAttribute.TYPE.WATERTANK,
stateAttrs.AttachmentStateAttribute.TYPE.MOP,
]
};
}
}

ViomiValetudoRobot.DEVICE_CONF_PATH = "/etc/miio/device.conf";
Expand Down
1 change: 1 addition & 0 deletions backend/lib/webserver/RobotRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class RobotRouter {
res.json({
manufacturer: this.robot.getManufacturer(),
modelName: this.robot.getModelName(),
modelDetails: this.robot.getModelDetails(),
implementation: this.robot.constructor.name
});
});
Expand Down
12 changes: 12 additions & 0 deletions backend/lib/webserver/doc/RobotRouter.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
"modelName": {
"type": "string"
},
"modelDetails": {
"type": "object",
"properties": {
"supportedAttachments": {
"type": "array",
"description": "Attachments that are detected and reported by the robot",
"items": {
"$ref": "#/components/schemas/AttachmentStateAttributeType"
}
}
}
},
"implementation": {
"type": "string",
"description": "Valetudo robot implementation in use"
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/api/RawRobotState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ export interface PresetSelectionState {
customValue?: number;
}

export type AttachmentStateAttributeType = "dustbin" | "watertank" | "mop";

export interface AttachmentState {
__class: RobotAttributeClass.AttachmentState;
type: "dustbin" | "watertank" | "mop";
type: AttachmentStateAttributeType;
attached: boolean;
}

Expand Down
5 changes: 5 additions & 0 deletions frontend/src/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {AttachmentStateAttributeType} from "./RawRobotState";

export enum Capability {
AutoEmptyDockAutoEmptyControl = "AutoEmptyDockAutoEmptyControlCapability",
AutoEmptyDockManualTrigger = "AutoEmptyDockManualTriggerCapability",
Expand Down Expand Up @@ -83,6 +85,9 @@ export interface Segment {
export interface RobotInformation {
manufacturer: string;
modelName: string;
modelDetails: {
supportedAttachments: Array<AttachmentStateAttributeType>;
}
implementation: string;
}

Expand Down
46 changes: 24 additions & 22 deletions frontend/src/controls/Attachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Box, Grid, Paper, Typography, ToggleButton, ToggleButtonGroup} from "@mu
import React from "react";
import LoadingFade from "../components/LoadingFade";

const Attachments = (): JSX.Element => {
const Attachments = (): JSX.Element | null => {
const {
data: attachments,
isLoading: isAttachmentLoading,
Expand Down Expand Up @@ -44,29 +44,31 @@ const Attachments = (): JSX.Element => {
}, [attachments, isAttachmentError]);

return (
<Paper>
<Grid container direction="column">
<Box px={2} pt={1}>
<Grid item container alignItems="center" spacing={1}>
<Grid item>
<Typography variant="subtitle1">
Attachments
</Typography>
<Grid item>
<Paper>
<Grid container direction="column">
<Box px={2} pt={1}>
<Grid item container alignItems="center" spacing={1}>
<Grid item>
<Typography variant="subtitle1">
Attachments
</Typography>
</Grid>
<Grid item>
<LoadingFade
in={isAttachmentLoading}
transitionDelay={isAttachmentLoading ? "500ms" : "0ms"}
size={20}
/>
</Grid>
</Grid>
<Grid item>
<LoadingFade
in={isAttachmentLoading}
transitionDelay={isAttachmentLoading ? "500ms" : "0ms"}
size={20}
/>
<Grid container direction="row" sx={{paddingBottom: "8px", paddingTop: "8px", maxHeight: "4em"}}>
{attachmentDetails}
</Grid>
</Grid>
<Grid container direction="row" sx={{paddingBottom: "8px", paddingTop: "8px", maxHeight: "4em"}}>
{attachmentDetails}
</Grid>
</Box>
</Grid>
</Paper>
</Box>
</Grid>
</Paper>
</Grid>
);
};

Expand Down
Loading

0 comments on commit fe65df3

Please sign in to comment.