1 """Support for Samsung Printers with SyncThru web interface."""
3 from __future__
import annotations
5 from pysyncthru
import SyncThru, SyncthruState
8 BinarySensorDeviceClass,
18 DataUpdateCoordinator,
21 from .
import device_identifiers
22 from .const
import DOMAIN
24 SYNCTHRU_STATE_PROBLEM = {
25 SyncthruState.INVALID:
True,
26 SyncthruState.OFFLINE:
None,
27 SyncthruState.NORMAL:
False,
28 SyncthruState.UNKNOWN:
True,
29 SyncthruState.WARNING:
True,
30 SyncthruState.TESTING:
False,
31 SyncthruState.ERROR:
True,
37 config_entry: ConfigEntry,
38 async_add_entities: AddEntitiesCallback,
40 """Set up from config entry."""
42 coordinator: DataUpdateCoordinator[SyncThru] = hass.data[DOMAIN][
46 name: str = config_entry.data[CONF_NAME]
56 CoordinatorEntity[DataUpdateCoordinator[SyncThru]], BinarySensorEntity
58 """Implementation of an abstract Samsung Printer binary sensor platform."""
60 def __init__(self, coordinator: DataUpdateCoordinator[SyncThru], name: str) ->
None:
61 """Initialize the sensor."""
69 """Return unique ID for the sensor."""
70 serial = self.
syncthrusyncthru.serial_number()
71 return f
"{serial}{self._id_suffix}" if serial
else None
75 """Return device information."""
79 identifiers=identifiers,
84 """Implementation of a sensor that checks whether is turned on/online."""
86 _attr_device_class = BinarySensorDeviceClass.CONNECTIVITY
88 def __init__(self, coordinator: DataUpdateCoordinator[SyncThru], name: str) ->
None:
89 """Initialize the sensor."""
95 """Set the state to whether the printer is online."""
96 return self.
syncthrusyncthru.is_online()
100 """Implementation of a sensor that checks whether the printer works correctly."""
102 _attr_device_class = BinarySensorDeviceClass.PROBLEM
105 """Initialize the sensor."""
111 """Set the state to whether there is a problem with the printer."""
112 return SYNCTHRU_STATE_PROBLEM[self.
syncthrusyncthru.device_status()]
None __init__(self, DataUpdateCoordinator[SyncThru] coordinator, str name)
DeviceInfo|None device_info(self)
None __init__(self, DataUpdateCoordinator[SyncThru] coordinator, str name)
def __init__(self, syncthru, name)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
set[tuple[str, str]]|None device_identifiers(SyncThru printer)