Add more PrusaLink sensors (#80424)
* Add more PrusaLink sensors * Disable prusalink target temperatures by default, add prusa to brands * Disable prusalink z-height by default * Remove uneccessary Prusa from brands * Move target temperatures to the telemetry section of the sensor * Fix entity naming for prusalink * Add tests for new prusalink sensors * Test fixes, fix rebase errors * Clean up deprecated unit usage * Add translations for entity names * Fix tests for translations --------- Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
b76551cf35
commit
48a2fe9e7a
4 changed files with 89 additions and 3 deletions
|
@ -15,7 +15,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import PERCENTAGE, UnitOfTemperature
|
from homeassistant.const import PERCENTAGE, UnitOfLength, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
@ -81,6 +81,45 @@ SENSORS: dict[str, tuple[PrusaLinkSensorEntityDescription, ...]] = {
|
||||||
value_fn=lambda data: cast(float, data["telemetry"]["temp-nozzle"]),
|
value_fn=lambda data: cast(float, data["telemetry"]["temp-nozzle"]),
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
|
PrusaLinkSensorEntityDescription[PrinterInfo](
|
||||||
|
key="printer.telemetry.temp-bed.target",
|
||||||
|
translation_key="heatbed_target_temperature",
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_fn=lambda data: cast(float, data["temperature"]["bed"]["target"]),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
PrusaLinkSensorEntityDescription[PrinterInfo](
|
||||||
|
key="printer.telemetry.temp-nozzle.target",
|
||||||
|
translation_key="nozzle_target_temperature",
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_fn=lambda data: cast(float, data["temperature"]["tool0"]["target"]),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
PrusaLinkSensorEntityDescription[PrinterInfo](
|
||||||
|
key="printer.telemetry.z-height",
|
||||||
|
translation_key="z_height",
|
||||||
|
native_unit_of_measurement=UnitOfLength.MILLIMETERS,
|
||||||
|
device_class=SensorDeviceClass.DISTANCE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_fn=lambda data: cast(float, data["telemetry"]["z-height"]),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
PrusaLinkSensorEntityDescription[PrinterInfo](
|
||||||
|
key="printer.telemetry.print-speed",
|
||||||
|
translation_key="print_speed",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
value_fn=lambda data: cast(float, data["telemetry"]["print-speed"]),
|
||||||
|
),
|
||||||
|
PrusaLinkSensorEntityDescription[PrinterInfo](
|
||||||
|
key="printer.telemetry.material",
|
||||||
|
translation_key="material",
|
||||||
|
icon="mdi:palette-swatch-variant",
|
||||||
|
value_fn=lambda data: cast(str, data["telemetry"]["material"]),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
"job": (
|
"job": (
|
||||||
PrusaLinkSensorEntityDescription[JobInfo](
|
PrusaLinkSensorEntityDescription[JobInfo](
|
||||||
|
|
|
@ -29,20 +29,35 @@
|
||||||
"heatbed_temperature": {
|
"heatbed_temperature": {
|
||||||
"name": "Heatbed temperature"
|
"name": "Heatbed temperature"
|
||||||
},
|
},
|
||||||
|
"heatbed_target_temperature": {
|
||||||
|
"name": "Heatbed target temperature"
|
||||||
|
},
|
||||||
"nozzle_temperature": {
|
"nozzle_temperature": {
|
||||||
"name": "Nozzle temperature"
|
"name": "Nozzle temperature"
|
||||||
},
|
},
|
||||||
|
"nozzle_target_temperature": {
|
||||||
|
"name": "Nozzle target temperature"
|
||||||
|
},
|
||||||
"progress": {
|
"progress": {
|
||||||
"name": "Progress"
|
"name": "Progress"
|
||||||
},
|
},
|
||||||
"filename": {
|
"filename": {
|
||||||
"name": "Filename"
|
"name": "Filename"
|
||||||
},
|
},
|
||||||
|
"material": {
|
||||||
|
"name": "Material"
|
||||||
|
},
|
||||||
"print_start": {
|
"print_start": {
|
||||||
"name": "Print start"
|
"name": "Print start"
|
||||||
},
|
},
|
||||||
"print_finish": {
|
"print_finish": {
|
||||||
"name": "Print finish"
|
"name": "Print finish"
|
||||||
|
},
|
||||||
|
"print_speed": {
|
||||||
|
"name": "Print speed"
|
||||||
|
},
|
||||||
|
"z_height": {
|
||||||
|
"name": "Z-Height"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
|
|
|
@ -42,8 +42,8 @@ def mock_printer_api(hass):
|
||||||
"material": "PLA",
|
"material": "PLA",
|
||||||
},
|
},
|
||||||
"temperature": {
|
"temperature": {
|
||||||
"tool0": {"actual": 47.8, "target": 0.0, "display": 0.0, "offset": 0},
|
"tool0": {"actual": 47.8, "target": 210.1, "display": 0.0, "offset": 0},
|
||||||
"bed": {"actual": 41.9, "target": 0.0, "offset": 0},
|
"bed": {"actual": 41.9, "target": 60.5, "offset": 0},
|
||||||
},
|
},
|
||||||
"state": {
|
"state": {
|
||||||
"text": "Operational",
|
"text": "Operational",
|
||||||
|
|
|
@ -14,7 +14,9 @@ from homeassistant.components.sensor import (
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_DEVICE_CLASS,
|
ATTR_DEVICE_CLASS,
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
|
PERCENTAGE,
|
||||||
Platform,
|
Platform,
|
||||||
|
UnitOfLength,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -63,6 +65,36 @@ async def test_sensors_no_job(hass: HomeAssistant, mock_config_entry, mock_api)
|
||||||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.TEMPERATURE
|
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.TEMPERATURE
|
||||||
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.mock_title_heatbed_target_temperature")
|
||||||
|
assert state is not None
|
||||||
|
assert state.state == "60.5"
|
||||||
|
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS
|
||||||
|
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.TEMPERATURE
|
||||||
|
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.mock_title_nozzle_target_temperature")
|
||||||
|
assert state is not None
|
||||||
|
assert state.state == "210.1"
|
||||||
|
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS
|
||||||
|
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.TEMPERATURE
|
||||||
|
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.mock_title_z_height")
|
||||||
|
assert state is not None
|
||||||
|
assert state.state == "1.8"
|
||||||
|
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfLength.MILLIMETERS
|
||||||
|
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.DISTANCE
|
||||||
|
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.mock_title_print_speed")
|
||||||
|
assert state is not None
|
||||||
|
assert state.state == "100"
|
||||||
|
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
|
||||||
|
|
||||||
|
state = hass.states.get("sensor.mock_title_material")
|
||||||
|
assert state is not None
|
||||||
|
assert state.state == "PLA"
|
||||||
|
|
||||||
state = hass.states.get("sensor.mock_title_progress")
|
state = hass.states.get("sensor.mock_title_progress")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "unavailable"
|
assert state.state == "unavailable"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue