Skip to content

Commit

Permalink
feat(mqtt): Expose battery state and status flag as home assistant se…
Browse files Browse the repository at this point in the history
…nsor entities
  • Loading branch information
Hypfer committed Jul 29, 2023
1 parent 0f390e0 commit 5f26145
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
21 changes: 21 additions & 0 deletions backend/lib/mqtt/status/BatteryStateMqttHandle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const ComponentType = require("../homeassistant/ComponentType");
const DataType = require("../homie/DataType");
const EntityCategory = require("../homeassistant/EntityCategory");
const HassAnchor = require("../homeassistant/HassAnchor");
const InLineHassComponent = require("../homeassistant/components/InLineHassComponent");
const Logger = require("../../Logger");
const PropertyMqttHandle = require("../handles/PropertyMqttHandle");
const RobotStateNodeMqttHandle = require("../handles/RobotStateNodeMqttHandle");
Expand Down Expand Up @@ -41,6 +44,24 @@ class BatteryStateMqttHandle extends RobotStateNodeMqttHandle {

return batteryState.level;
}
}).also((prop) => {
this.controller.withHass((hass => {
prop.attachHomeAssistantComponent(
new InLineHassComponent({
hass: hass,
robot: this.robot,
name: "battery_level",
friendlyName: "Battery level",
componentType: ComponentType.SENSOR,
autoconf: {
state_topic: prop.getBaseTopic(),
icon: "mdi:battery",
entity_category: EntityCategory.DIAGNOSTIC,
unit_of_measurement: Unit.PERCENT
}
})
);
}));
}));

this.registerChild(new PropertyMqttHandle({
Expand Down
17 changes: 17 additions & 0 deletions backend/lib/mqtt/status/StatusStateMqttHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ class StatusStateMqttHandle extends RobotStateNodeMqttHandle {
}
return statusState.flag;
}
}).also((prop) => {
this.controller.withHass((hass => {
prop.attachHomeAssistantComponent(
new InLineHassComponent({
hass: hass,
robot: this.robot,
name: "status_flag",
friendlyName: "Status Flag",
componentType: ComponentType.SENSOR,
autoconf: {
state_topic: prop.getBaseTopic(),
icon: "mdi:flag",
entity_category: EntityCategory.DIAGNOSTIC
}
})
);
}));
}));

this.registerChild(new PropertyMqttHandle({
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/robot/RobotOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const CarpetModeControlCapabilitySwitchListMenuItem = () => {
}}
disabled={disabled}
loadError={isError}
primaryLabel={"Carpet mode"}
primaryLabel={"Carpet Mode"}
secondaryLabel={"When enabled, the vacuum will recognize carpets automatically and increase the suction."}
icon={<CarpetModeIcon/>}
/>
Expand Down Expand Up @@ -186,7 +186,7 @@ const CarpetSensorModeControlCapabilitySelectListMenuItem = () => {
disabled={disabled}
loadingOptions={carpetSensorModePropertiesLoading || isLoading}
loadError={carpetSensorModePropertiesError}
primaryLabel="Carpet Sensor Mode"
primaryLabel="Carpet Sensor"
secondaryLabel="Select what action the robot should take if it detects carpet while mopping."
icon={<CarpetSensorModeIcon/>}
/>
Expand Down

0 comments on commit 5f26145

Please sign in to comment.