Skip to content

Commit

Permalink
Merge pull request #626 from lukasjakobi/612-battery-as-sensor-entity
Browse files Browse the repository at this point in the history
add battery sensor entity
  • Loading branch information
humbertogontijo committed Apr 29, 2024
2 parents aa417de + 4634ca5 commit 595676c
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ There is a map built in to the integration that shows you your most recent/curre
- side brush left
- filter left
- sensor dirty left
- battery

### Binary Sensors
- Mop attached
Expand Down
10 changes: 10 additions & 0 deletions custom_components/roborock/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@ class RoborockSensorDescription(SensorEntityDescription):
translation_key="clean_percent",
entity_category=EntityCategory.DIAGNOSTIC,
),
f"current_{ATTR_BATTERY}": RoborockSensorDescription(
native_unit_of_measurement=PERCENTAGE,
key="battery",
icon="mdi:battery",
name="Battery",
translation_key="battery",
device_class=SensorDeviceClass.BATTERY,
parent_key="status",
entity_category=EntityCategory.DIAGNOSTIC,
),
}

VACUUM_WITH_DOCK_SENSORS = {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@
},
"clean_percent": {
"name": "Průběh úklidu"
},
"battery": {
"name": "Baterie"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
},
"dock_status": {
"name": "Dock status"
},
"battery": {
"name": "Batteri"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@
},
"clean_percent": {
"name": "Reinigungsprozess"
},
"battery": {
"name": "Batterie"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@
},
"clean_percent": {
"name": "Cleaning progress"
},
"battery": {
"name": "Battery"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@
},
"clean_percent": {
"name": "Progression nettoyage"
},
"battery": {
"name": "Batterie"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@
},
"clean_percent": {
"name": "התקדמות הניקוי"
},
"battery": {
"name": "סוֹלְלָה"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@
},
"clean_percent": {
"name": "Progresso pulizia"
},
"battery": {
"name": "Batteria"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/lv.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@
},
"clean_percent": {
"name": "Uzkopšanas progress"
},
"battery": {
"name": "Akumulators"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
},
"dock_status": {
"name": "Dock status"
},
"battery": {
"name": "Accu"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
},
"dock_status": {
"name": "Dock status"
},
"battery": {
"name": "Batteri"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
},
"dock_status": {
"name": "Dock status"
},
"battery": {
"name": "Bateria"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
},
"dock_status": {
"name": "Estado da dock"
},
"battery": {
"name": "Batteria"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
},
"dock_status": {
"name": "Состояние док-станции"
},
"battery": {
"name": "Батарея"
}
},
"binary_sensor": {
Expand Down
3 changes: 3 additions & 0 deletions custom_components/roborock/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
},
"dock_status": {
"name": "Dockningsstatus"
},
"battery": {
"name": "Batteri"
}
},
"binary_sensor": {
Expand Down
11 changes: 11 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,14 @@ async def test_sensor_dirty_left(hass: HomeAssistant, bypass_api_fixture) -> Non
assert state.state == str(SENSOR_DIRTY_REPLACE_TIME - CONSUMABLE.sensor_dirty_time)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.DURATION
await mock_config_entry.async_unload(hass)


@pytest.mark.asyncio
async def test_battery(hass: HomeAssistant, bypass_api_fixture) -> None:
"""Tests battery is getting the correct values."""
mock_config_entry = await setup_platform(hass, SENSOR_DOMAIN)
state = hass.states.get("sensor.roborock_s7_maxv_battery")

assert state.state == STATUS.battery
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.BATTERY
await mock_config_entry.async_unload(hass)

0 comments on commit 595676c

Please sign in to comment.