1 """Support for Samsung Printers with SyncThru web interface."""
3 from __future__
import annotations
5 from pysyncthru
import SyncThru, SyncthruState
15 DataUpdateCoordinator,
18 from .
import device_identifiers
19 from .const
import DOMAIN
21 COLORS = [
"black",
"cyan",
"magenta",
"yellow"]
25 OUTPUT_TRAYS = range(6)
26 DEFAULT_MONITORED_CONDITIONS = []
27 DEFAULT_MONITORED_CONDITIONS.extend([f
"toner_{key}" for key
in TONER_COLORS])
28 DEFAULT_MONITORED_CONDITIONS.extend([f
"drum_{key}" for key
in DRUM_COLORS])
29 DEFAULT_MONITORED_CONDITIONS.extend([f
"tray_{key}" for key
in TRAYS])
30 DEFAULT_MONITORED_CONDITIONS.extend([f
"output_tray_{key}" for key
in OUTPUT_TRAYS])
32 SYNCTHRU_STATE_HUMAN = {
33 SyncthruState.INVALID:
"invalid",
34 SyncthruState.OFFLINE:
"unreachable",
35 SyncthruState.NORMAL:
"normal",
36 SyncthruState.UNKNOWN:
"unknown",
37 SyncthruState.WARNING:
"warning",
38 SyncthruState.TESTING:
"testing",
39 SyncthruState.ERROR:
"error",
45 config_entry: ConfigEntry,
46 async_add_entities: AddEntitiesCallback,
48 """Set up from config entry."""
50 coordinator: DataUpdateCoordinator[SyncThru] = hass.data[DOMAIN][
53 printer: SyncThru = coordinator.data
55 supp_toner = printer.toner_status(filter_supported=
True)
56 supp_drum = printer.drum_status(filter_supported=
True)
57 supp_tray = printer.input_tray_status(filter_supported=
True)
58 supp_output_tray = printer.output_tray_status()
60 name: str = config_entry.data[CONF_NAME]
61 entities: list[SyncThruSensor] = [
72 for int_key
in supp_output_tray
79 """Implementation of an abstract Samsung Printer sensor platform."""
81 _attr_icon =
"mdi:printer"
83 def __init__(self, coordinator: DataUpdateCoordinator[SyncThru], name: str) ->
None:
84 """Initialize the sensor."""
92 """Return unique ID for the sensor."""
93 serial = self.
syncthrusyncthru.serial_number()
94 return f
"{serial}{self._id_suffix}" if serial
else None
98 """Return device information."""
102 identifiers=identifiers,
107 """Implementation of the main sensor, conducting the actual polling.
109 It also shows the detailed state and presents
110 the displayed current status message.
113 _attr_entity_registry_enabled_default =
False
115 def __init__(self, coordinator: DataUpdateCoordinator[SyncThru], name: str) ->
None:
116 """Initialize the sensor."""
122 """Set state to human readable version of syncthru status."""
123 return SYNCTHRU_STATE_HUMAN[self.
syncthrusyncthru.device_status()]
127 """Show current printer display text."""
129 "display_text": self.
syncthrusyncthru.device_status_details(),
134 """Implementation of a Samsung Printer toner sensor platform."""
136 _attr_native_unit_of_measurement = PERCENTAGE
139 self, coordinator: DataUpdateCoordinator[SyncThru], name: str, color: str
141 """Initialize the sensor."""
149 """Show all data returned for this toner."""
154 """Show amount of remaining toner."""
159 """Implementation of a Samsung Printer drum sensor platform."""
161 _attr_native_unit_of_measurement = PERCENTAGE
164 self, coordinator: DataUpdateCoordinator[SyncThru], name: str, color: str
166 """Initialize the sensor."""
174 """Show all data returned for this drum."""
179 """Show amount of remaining drum."""
184 """Implementation of a Samsung Printer input tray sensor platform."""
187 self, coordinator: DataUpdateCoordinator[SyncThru], name: str, number: str
189 """Initialize the sensor."""
197 """Show all data returned for this input tray."""
202 """Display ready unless there is some error, then display error."""
212 """Implementation of a Samsung Printer output tray sensor platform."""
215 self, coordinator: DataUpdateCoordinator[SyncThru], name: str, number: int
217 """Initialize the sensor."""
225 """Show all data returned for this output tray."""
230 """Display ready unless there is some error, then display error."""
240 """Implementation of a Samsung Printer active alerts sensor platform."""
242 def __init__(self, coordinator: DataUpdateCoordinator[SyncThru], name: str) ->
None:
243 """Initialize the sensor."""
250 """Show number of active alerts."""
251 return self.
syncthrusyncthru.raw().
get(
"GXI_ACTIVE_ALERT_TOTAL")
None __init__(self, DataUpdateCoordinator[SyncThru] coordinator, str name)
None __init__(self, DataUpdateCoordinator[SyncThru] coordinator, str name, str color)
def extra_state_attributes(self)
def extra_state_attributes(self)
None __init__(self, DataUpdateCoordinator[SyncThru] coordinator, str name)
def extra_state_attributes(self)
None __init__(self, DataUpdateCoordinator[SyncThru] coordinator, str name, int number)
DeviceInfo|None device_info(self)
None __init__(self, DataUpdateCoordinator[SyncThru] coordinator, str name)
None __init__(self, DataUpdateCoordinator[SyncThru] coordinator, str name, str color)
def extra_state_attributes(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
set[tuple[str, str]]|None device_identifiers(SyncThru printer)