mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Use attributes octoprint (#58241)
This commit is contained in:
parent
b0b49c611e
commit
823ca7ee40
@ -52,9 +52,9 @@ class OctoPrintBinarySensorBase(CoordinatorEntity, BinarySensorEntity):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a new OctoPrint sensor."""
|
"""Initialize a new OctoPrint sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._name = f"Octoprint {sensor_type}"
|
|
||||||
self.sensor_type = sensor_type
|
|
||||||
self._device_id = device_id
|
self._device_id = device_id
|
||||||
|
self._attr_name = f"Octoprint {sensor_type}"
|
||||||
|
self._attr_unique_id = f"{sensor_type}-{device_id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
@ -65,16 +65,6 @@ class OctoPrintBinarySensorBase(CoordinatorEntity, BinarySensorEntity):
|
|||||||
"name": "Octoprint",
|
"name": "Octoprint",
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique id."""
|
|
||||||
return f"{self.sensor_type}-{self._device_id}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if binary sensor is on."""
|
"""Return true if binary sensor is on."""
|
||||||
|
@ -75,9 +75,9 @@ class OctoPrintSensorBase(CoordinatorEntity, SensorEntity):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a new OctoPrint sensor."""
|
"""Initialize a new OctoPrint sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._sensor_type = sensor_type
|
|
||||||
self._name = f"Octoprint {sensor_type}"
|
|
||||||
self._device_id = device_id
|
self._device_id = device_id
|
||||||
|
self._attr_name = f"Octoprint {sensor_type}"
|
||||||
|
self._attr_unique_id = f"{sensor_type}-{device_id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
@ -88,20 +88,12 @@ class OctoPrintSensorBase(CoordinatorEntity, SensorEntity):
|
|||||||
"name": "Octoprint",
|
"name": "Octoprint",
|
||||||
}
|
}
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique id."""
|
|
||||||
return f"{self._sensor_type}-{self._device_id}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
|
|
||||||
class OctoPrintStatusSensor(OctoPrintSensorBase):
|
class OctoPrintStatusSensor(OctoPrintSensorBase):
|
||||||
"""Representation of an OctoPrint sensor."""
|
"""Representation of an OctoPrint sensor."""
|
||||||
|
|
||||||
|
_attr_icon = "mdi:printer-3d"
|
||||||
|
|
||||||
def __init__(self, coordinator: DataUpdateCoordinator, device_id: str) -> None:
|
def __init__(self, coordinator: DataUpdateCoordinator, device_id: str) -> None:
|
||||||
"""Initialize a new OctoPrint sensor."""
|
"""Initialize a new OctoPrint sensor."""
|
||||||
super().__init__(coordinator, "Current State", device_id)
|
super().__init__(coordinator, "Current State", device_id)
|
||||||
@ -115,11 +107,6 @@ class OctoPrintStatusSensor(OctoPrintSensorBase):
|
|||||||
|
|
||||||
return printer.state.text
|
return printer.state.text
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Icon to use in the frontend."""
|
|
||||||
return "mdi:printer-3d"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return if entity is available."""
|
"""Return if entity is available."""
|
||||||
@ -129,6 +116,9 @@ class OctoPrintStatusSensor(OctoPrintSensorBase):
|
|||||||
class OctoPrintJobPercentageSensor(OctoPrintSensorBase):
|
class OctoPrintJobPercentageSensor(OctoPrintSensorBase):
|
||||||
"""Representation of an OctoPrint sensor."""
|
"""Representation of an OctoPrint sensor."""
|
||||||
|
|
||||||
|
_attr_native_unit_of_measurement = PERCENTAGE
|
||||||
|
_attr_icon = "mdi:file-percent"
|
||||||
|
|
||||||
def __init__(self, coordinator: DataUpdateCoordinator, device_id: str) -> None:
|
def __init__(self, coordinator: DataUpdateCoordinator, device_id: str) -> None:
|
||||||
"""Initialize a new OctoPrint sensor."""
|
"""Initialize a new OctoPrint sensor."""
|
||||||
super().__init__(coordinator, "Job Percentage", device_id)
|
super().__init__(coordinator, "Job Percentage", device_id)
|
||||||
@ -146,20 +136,12 @@ class OctoPrintJobPercentageSensor(OctoPrintSensorBase):
|
|||||||
|
|
||||||
return round(state, 2)
|
return round(state, 2)
|
||||||
|
|
||||||
@property
|
|
||||||
def native_unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
|
||||||
return PERCENTAGE
|
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Icon to use in the frontend."""
|
|
||||||
return "mdi:file-percent"
|
|
||||||
|
|
||||||
|
|
||||||
class OctoPrintEstimatedFinishTimeSensor(OctoPrintSensorBase):
|
class OctoPrintEstimatedFinishTimeSensor(OctoPrintSensorBase):
|
||||||
"""Representation of an OctoPrint sensor."""
|
"""Representation of an OctoPrint sensor."""
|
||||||
|
|
||||||
|
_attr_device_class = DEVICE_CLASS_TIMESTAMP
|
||||||
|
|
||||||
def __init__(self, coordinator: DataUpdateCoordinator, device_id: str) -> None:
|
def __init__(self, coordinator: DataUpdateCoordinator, device_id: str) -> None:
|
||||||
"""Initialize a new OctoPrint sensor."""
|
"""Initialize a new OctoPrint sensor."""
|
||||||
super().__init__(coordinator, "Estimated Finish Time", device_id)
|
super().__init__(coordinator, "Estimated Finish Time", device_id)
|
||||||
@ -175,15 +157,12 @@ class OctoPrintEstimatedFinishTimeSensor(OctoPrintSensorBase):
|
|||||||
|
|
||||||
return (read_time + timedelta(seconds=job.progress.print_time_left)).isoformat()
|
return (read_time + timedelta(seconds=job.progress.print_time_left)).isoformat()
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the device class of the sensor."""
|
|
||||||
return DEVICE_CLASS_TIMESTAMP
|
|
||||||
|
|
||||||
|
|
||||||
class OctoPrintStartTimeSensor(OctoPrintSensorBase):
|
class OctoPrintStartTimeSensor(OctoPrintSensorBase):
|
||||||
"""Representation of an OctoPrint sensor."""
|
"""Representation of an OctoPrint sensor."""
|
||||||
|
|
||||||
|
_attr_device_class = DEVICE_CLASS_TIMESTAMP
|
||||||
|
|
||||||
def __init__(self, coordinator: DataUpdateCoordinator, device_id: str) -> None:
|
def __init__(self, coordinator: DataUpdateCoordinator, device_id: str) -> None:
|
||||||
"""Initialize a new OctoPrint sensor."""
|
"""Initialize a new OctoPrint sensor."""
|
||||||
super().__init__(coordinator, "Start Time", device_id)
|
super().__init__(coordinator, "Start Time", device_id)
|
||||||
@ -200,15 +179,14 @@ class OctoPrintStartTimeSensor(OctoPrintSensorBase):
|
|||||||
|
|
||||||
return (read_time - timedelta(seconds=job.progress.print_time)).isoformat()
|
return (read_time - timedelta(seconds=job.progress.print_time)).isoformat()
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the device class of the sensor."""
|
|
||||||
return DEVICE_CLASS_TIMESTAMP
|
|
||||||
|
|
||||||
|
|
||||||
class OctoPrintTemperatureSensor(OctoPrintSensorBase):
|
class OctoPrintTemperatureSensor(OctoPrintSensorBase):
|
||||||
"""Representation of an OctoPrint sensor."""
|
"""Representation of an OctoPrint sensor."""
|
||||||
|
|
||||||
|
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
||||||
|
_attr_device_class = DEVICE_CLASS_TEMPERATURE
|
||||||
|
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: DataUpdateCoordinator,
|
coordinator: DataUpdateCoordinator,
|
||||||
@ -220,17 +198,6 @@ class OctoPrintTemperatureSensor(OctoPrintSensorBase):
|
|||||||
super().__init__(coordinator, f"{temp_type} {tool} temp", device_id)
|
super().__init__(coordinator, f"{temp_type} {tool} temp", device_id)
|
||||||
self._temp_type = temp_type
|
self._temp_type = temp_type
|
||||||
self._api_tool = tool
|
self._api_tool = tool
|
||||||
self._attr_state_class = STATE_CLASS_MEASUREMENT
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
|
||||||
return TEMP_CELSIUS
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the device class of this entity."""
|
|
||||||
return DEVICE_CLASS_TEMPERATURE
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user