Add SyncThru binary sensors (#48114)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
809c1394d4
commit
2eae87fb1b
7 changed files with 247 additions and 94 deletions
|
@ -967,6 +967,8 @@ omit =
|
||||||
homeassistant/components/switchbot/switch.py
|
homeassistant/components/switchbot/switch.py
|
||||||
homeassistant/components/switcher_kis/switch.py
|
homeassistant/components/switcher_kis/switch.py
|
||||||
homeassistant/components/switchmate/switch.py
|
homeassistant/components/switchmate/switch.py
|
||||||
|
homeassistant/components/syncthru/__init__.py
|
||||||
|
homeassistant/components/syncthru/binary_sensor.py
|
||||||
homeassistant/components/syncthru/sensor.py
|
homeassistant/components/syncthru/sensor.py
|
||||||
homeassistant/components/synology_chat/notify.py
|
homeassistant/components/synology_chat/notify.py
|
||||||
homeassistant/components/synology_dsm/__init__.py
|
homeassistant/components/synology_dsm/__init__.py
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
"""The syncthru component."""
|
"""The syncthru component."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
from pysyncthru import SyncThru
|
from pysyncthru import SyncThru
|
||||||
|
|
||||||
|
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_URL
|
from homeassistant.const import CONF_URL
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import aiohttp_client, device_registry as dr
|
from homeassistant.helpers import aiohttp_client, device_registry as dr
|
||||||
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORMS = [SENSOR_DOMAIN]
|
PLATFORMS = [BINARY_SENSOR_DOMAIN, SENSOR_DOMAIN]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
@ -24,21 +28,33 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
|
||||||
session = aiohttp_client.async_get_clientsession(hass)
|
session = aiohttp_client.async_get_clientsession(hass)
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
printer = hass.data[DOMAIN][entry.entry_id] = SyncThru(
|
printer = SyncThru(entry.data[CONF_URL], session)
|
||||||
entry.data[CONF_URL], session
|
|
||||||
)
|
|
||||||
|
|
||||||
|
async def async_update_data() -> SyncThru:
|
||||||
|
"""Fetch data from the printer."""
|
||||||
try:
|
try:
|
||||||
|
async with async_timeout.timeout(10):
|
||||||
await printer.update()
|
await printer.update()
|
||||||
except ValueError:
|
except ValueError as value_error:
|
||||||
_LOGGER.error(
|
# if an exception is thrown, printer does not support syncthru
|
||||||
"Device at %s not appear to be a SyncThru printer, aborting setup",
|
raise UpdateFailed(
|
||||||
printer.url,
|
f"Configured printer at {printer.url} does not respond. "
|
||||||
)
|
"Please make sure it supports SyncThru and check your configuration."
|
||||||
return False
|
) from value_error
|
||||||
else:
|
else:
|
||||||
if printer.is_unknown_state():
|
if printer.is_unknown_state():
|
||||||
raise ConfigEntryNotReady
|
raise ConfigEntryNotReady
|
||||||
|
return printer
|
||||||
|
|
||||||
|
coordinator: DataUpdateCoordinator = DataUpdateCoordinator(
|
||||||
|
hass,
|
||||||
|
_LOGGER,
|
||||||
|
name=DOMAIN,
|
||||||
|
update_method=async_update_data,
|
||||||
|
update_interval=timedelta(seconds=30),
|
||||||
|
)
|
||||||
|
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||||
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
device_registry = await dr.async_get_registry(hass)
|
device_registry = await dr.async_get_registry(hass)
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
|
@ -60,9 +76,12 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
def device_identifiers(printer: SyncThru) -> set[tuple[str, ...]]:
|
def device_identifiers(printer: SyncThru) -> set[tuple[str, ...]] | None:
|
||||||
"""Get device identifiers for device registry."""
|
"""Get device identifiers for device registry."""
|
||||||
return {(DOMAIN, printer.serial_number())}
|
serial = printer.serial_number()
|
||||||
|
if serial is None:
|
||||||
|
return None
|
||||||
|
return {(DOMAIN, serial)}
|
||||||
|
|
||||||
|
|
||||||
def device_connections(printer: SyncThru) -> set[tuple[str, str]]:
|
def device_connections(printer: SyncThru) -> set[tuple[str, str]]:
|
||||||
|
|
110
homeassistant/components/syncthru/binary_sensor.py
Normal file
110
homeassistant/components/syncthru/binary_sensor.py
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
"""Support for Samsung Printers with SyncThru web interface."""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from pysyncthru import SyncThru, SyncthruState
|
||||||
|
|
||||||
|
from homeassistant.components.binary_sensor import (
|
||||||
|
DEVICE_CLASS_CONNECTIVITY,
|
||||||
|
DEVICE_CLASS_PROBLEM,
|
||||||
|
BinarySensorEntity,
|
||||||
|
)
|
||||||
|
from homeassistant.const import CONF_NAME
|
||||||
|
from homeassistant.helpers.update_coordinator import (
|
||||||
|
CoordinatorEntity,
|
||||||
|
DataUpdateCoordinator,
|
||||||
|
)
|
||||||
|
|
||||||
|
from . import device_identifiers
|
||||||
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
SYNCTHRU_STATE_PROBLEM = {
|
||||||
|
SyncthruState.INVALID: True,
|
||||||
|
SyncthruState.OFFLINE: None,
|
||||||
|
SyncthruState.NORMAL: False,
|
||||||
|
SyncthruState.UNKNOWN: True,
|
||||||
|
SyncthruState.WARNING: True,
|
||||||
|
SyncthruState.TESTING: False,
|
||||||
|
SyncthruState.ERROR: True,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
|
"""Set up from config entry."""
|
||||||
|
|
||||||
|
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
|
name = config_entry.data[CONF_NAME]
|
||||||
|
entities = [
|
||||||
|
SyncThruOnlineSensor(coordinator, name),
|
||||||
|
SyncThruProblemSensor(coordinator, name),
|
||||||
|
]
|
||||||
|
|
||||||
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
|
class SyncThruBinarySensor(CoordinatorEntity, BinarySensorEntity):
|
||||||
|
"""Implementation of an abstract Samsung Printer binary sensor platform."""
|
||||||
|
|
||||||
|
def __init__(self, coordinator, name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
self.syncthru: SyncThru = coordinator.data
|
||||||
|
self._name = name
|
||||||
|
self._id_suffix = ""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return unique ID for the sensor."""
|
||||||
|
serial = self.syncthru.serial_number()
|
||||||
|
return f"{serial}{self._id_suffix}" if serial else None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return the name of the sensor."""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_info(self):
|
||||||
|
"""Return device information."""
|
||||||
|
return {"identifiers": device_identifiers(self.syncthru)}
|
||||||
|
|
||||||
|
|
||||||
|
class SyncThruOnlineSensor(SyncThruBinarySensor):
|
||||||
|
"""Implementation of a sensor that checks whether is turned on/online."""
|
||||||
|
|
||||||
|
def __init__(self, syncthru, name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
super().__init__(syncthru, name)
|
||||||
|
self._id_suffix = "_online"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Class of the sensor."""
|
||||||
|
return DEVICE_CLASS_CONNECTIVITY
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self):
|
||||||
|
"""Set the state to whether the printer is online."""
|
||||||
|
return self.syncthru.is_online()
|
||||||
|
|
||||||
|
|
||||||
|
class SyncThruProblemSensor(SyncThruBinarySensor):
|
||||||
|
"""Implementation of a sensor that checks whether the printer works correctly."""
|
||||||
|
|
||||||
|
def __init__(self, syncthru, name):
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
super().__init__(syncthru, name)
|
||||||
|
self._id_suffix = "_problem"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Class of the sensor."""
|
||||||
|
return DEVICE_CLASS_PROBLEM
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self):
|
||||||
|
"""Set the state to whether there is a problem with the printer."""
|
||||||
|
return SYNCTHRU_STATE_PROBLEM[self.syncthru.device_status()]
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Samsung SyncThru Printer",
|
"name": "Samsung SyncThru Printer",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/syncthru",
|
"documentation": "https://www.home-assistant.io/integrations/syncthru",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"requirements": ["pysyncthru==0.7.0", "url-normalize==1.4.1"],
|
"requirements": ["pysyncthru==0.7.3", "url-normalize==1.4.1"],
|
||||||
"ssdp": [
|
"ssdp": [
|
||||||
{
|
{
|
||||||
"deviceType": "urn:schemas-upnp-org:device:Printer:1",
|
"deviceType": "urn:schemas-upnp-org:device:Printer:1",
|
||||||
|
|
|
@ -2,13 +2,17 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pysyncthru import SYNCTHRU_STATE_HUMAN, SyncThru
|
from pysyncthru import SyncThru, SyncthruState
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT
|
from homeassistant.config_entries import SOURCE_IMPORT
|
||||||
from homeassistant.const import CONF_NAME, CONF_RESOURCE, CONF_URL, PERCENTAGE
|
from homeassistant.const import CONF_NAME, CONF_RESOURCE, CONF_URL, PERCENTAGE
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.update_coordinator import (
|
||||||
|
CoordinatorEntity,
|
||||||
|
DataUpdateCoordinator,
|
||||||
|
)
|
||||||
|
|
||||||
from . import device_identifiers
|
from . import device_identifiers
|
||||||
from .const import DEFAULT_MODEL, DEFAULT_NAME_TEMPLATE, DOMAIN
|
from .const import DEFAULT_MODEL, DEFAULT_NAME_TEMPLATE, DOMAIN
|
||||||
|
@ -26,6 +30,16 @@ DEFAULT_MONITORED_CONDITIONS.extend([f"drum_{key}" for key in DRUM_COLORS])
|
||||||
DEFAULT_MONITORED_CONDITIONS.extend([f"tray_{key}" for key in TRAYS])
|
DEFAULT_MONITORED_CONDITIONS.extend([f"tray_{key}" for key in TRAYS])
|
||||||
DEFAULT_MONITORED_CONDITIONS.extend([f"output_tray_{key}" for key in OUTPUT_TRAYS])
|
DEFAULT_MONITORED_CONDITIONS.extend([f"output_tray_{key}" for key in OUTPUT_TRAYS])
|
||||||
|
|
||||||
|
SYNCTHRU_STATE_HUMAN = {
|
||||||
|
SyncthruState.INVALID: "invalid",
|
||||||
|
SyncthruState.OFFLINE: "unreachable",
|
||||||
|
SyncthruState.NORMAL: "normal",
|
||||||
|
SyncthruState.UNKNOWN: "unknown",
|
||||||
|
SyncthruState.WARNING: "warning",
|
||||||
|
SyncthruState.TESTING: "testing",
|
||||||
|
SyncthruState.ERROR: "error",
|
||||||
|
}
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_RESOURCE): cv.url,
|
vol.Required(CONF_RESOURCE): cv.url,
|
||||||
|
@ -58,7 +72,8 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Set up from config entry."""
|
"""Set up from config entry."""
|
||||||
|
|
||||||
printer = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
printer: SyncThru = coordinator.data
|
||||||
|
|
||||||
supp_toner = printer.toner_status(filter_supported=True)
|
supp_toner = printer.toner_status(filter_supported=True)
|
||||||
supp_drum = printer.drum_status(filter_supported=True)
|
supp_drum = printer.drum_status(filter_supported=True)
|
||||||
|
@ -66,28 +81,27 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
supp_output_tray = printer.output_tray_status()
|
supp_output_tray = printer.output_tray_status()
|
||||||
|
|
||||||
name = config_entry.data[CONF_NAME]
|
name = config_entry.data[CONF_NAME]
|
||||||
devices = [SyncThruMainSensor(printer, name)]
|
entities = [SyncThruMainSensor(coordinator, name)]
|
||||||
|
|
||||||
for key in supp_toner:
|
for key in supp_toner:
|
||||||
devices.append(SyncThruTonerSensor(printer, name, key))
|
entities.append(SyncThruTonerSensor(coordinator, name, key))
|
||||||
for key in supp_drum:
|
for key in supp_drum:
|
||||||
devices.append(SyncThruDrumSensor(printer, name, key))
|
entities.append(SyncThruDrumSensor(coordinator, name, key))
|
||||||
for key in supp_tray:
|
for key in supp_tray:
|
||||||
devices.append(SyncThruInputTraySensor(printer, name, key))
|
entities.append(SyncThruInputTraySensor(coordinator, name, key))
|
||||||
for key in supp_output_tray:
|
for key in supp_output_tray:
|
||||||
devices.append(SyncThruOutputTraySensor(printer, name, key))
|
entities.append(SyncThruOutputTraySensor(coordinator, name, key))
|
||||||
|
|
||||||
async_add_entities(devices, True)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
class SyncThruSensor(SensorEntity):
|
class SyncThruSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Implementation of an abstract Samsung Printer sensor platform."""
|
"""Implementation of an abstract Samsung Printer sensor platform."""
|
||||||
|
|
||||||
def __init__(self, syncthru, name):
|
def __init__(self, coordinator, name):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.syncthru: SyncThru = syncthru
|
super().__init__(coordinator)
|
||||||
self._attributes = {}
|
self.syncthru: SyncThru = coordinator.data
|
||||||
self._state = None
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._icon = "mdi:printer"
|
self._icon = "mdi:printer"
|
||||||
self._unit_of_measurement = None
|
self._unit_of_measurement = None
|
||||||
|
@ -97,18 +111,13 @@ class SyncThruSensor(SensorEntity):
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return unique ID for the sensor."""
|
"""Return unique ID for the sensor."""
|
||||||
serial = self.syncthru.serial_number()
|
serial = self.syncthru.serial_number()
|
||||||
return serial + self._id_suffix if serial else super().unique_id
|
return f"{serial}{self._id_suffix}" if serial else None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the device."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
"""Return the icon of the device."""
|
"""Return the icon of the device."""
|
||||||
|
@ -119,11 +128,6 @@ class SyncThruSensor(SensorEntity):
|
||||||
"""Return the unit of measuremnt."""
|
"""Return the unit of measuremnt."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self):
|
|
||||||
"""Return the state attributes of the device."""
|
|
||||||
return self._attributes
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
"""Return device information."""
|
"""Return device information."""
|
||||||
|
@ -131,50 +135,56 @@ class SyncThruSensor(SensorEntity):
|
||||||
|
|
||||||
|
|
||||||
class SyncThruMainSensor(SyncThruSensor):
|
class SyncThruMainSensor(SyncThruSensor):
|
||||||
"""Implementation of the main sensor, conducting the actual polling."""
|
"""
|
||||||
|
Implementation of the main sensor, conducting the actual polling.
|
||||||
|
|
||||||
def __init__(self, syncthru, name):
|
It also shows the detailed state and presents
|
||||||
|
the displayed current status message.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, coordinator, name):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(syncthru, name)
|
super().__init__(coordinator, name)
|
||||||
self._id_suffix = "_main"
|
self._id_suffix = "_main"
|
||||||
self._active = True
|
|
||||||
|
|
||||||
async def async_update(self):
|
@property
|
||||||
"""Get the latest data from SyncThru and update the state."""
|
def state(self):
|
||||||
if not self._active:
|
"""Set state to human readable version of syncthru status."""
|
||||||
return
|
return SYNCTHRU_STATE_HUMAN[self.syncthru.device_status()]
|
||||||
try:
|
|
||||||
await self.syncthru.update()
|
@property
|
||||||
except ValueError:
|
def extra_state_attributes(self):
|
||||||
# if an exception is thrown, printer does not support syncthru
|
"""Show current printer display text."""
|
||||||
_LOGGER.warning(
|
return {
|
||||||
"Configured printer at %s does not support SyncThru. "
|
"display_text": self.syncthru.device_status_details(),
|
||||||
"Consider changing your configuration",
|
}
|
||||||
self.syncthru.url,
|
|
||||||
)
|
@property
|
||||||
self._active = False
|
def entity_registry_enabled_default(self) -> bool:
|
||||||
self._state = SYNCTHRU_STATE_HUMAN[self.syncthru.device_status()]
|
"""Disable entity by default."""
|
||||||
self._attributes = {"display_text": self.syncthru.device_status_details()}
|
return False
|
||||||
|
|
||||||
|
|
||||||
class SyncThruTonerSensor(SyncThruSensor):
|
class SyncThruTonerSensor(SyncThruSensor):
|
||||||
"""Implementation of a Samsung Printer toner sensor platform."""
|
"""Implementation of a Samsung Printer toner sensor platform."""
|
||||||
|
|
||||||
def __init__(self, syncthru, name, color):
|
def __init__(self, coordinator, name, color):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(syncthru, name)
|
super().__init__(coordinator, name)
|
||||||
self._name = f"{name} Toner {color}"
|
self._name = f"{name} Toner {color}"
|
||||||
self._color = color
|
self._color = color
|
||||||
self._unit_of_measurement = PERCENTAGE
|
self._unit_of_measurement = PERCENTAGE
|
||||||
self._id_suffix = f"_toner_{color}"
|
self._id_suffix = f"_toner_{color}"
|
||||||
|
|
||||||
def update(self):
|
@property
|
||||||
"""Get the latest data from SyncThru and update the state."""
|
def extra_state_attributes(self):
|
||||||
# Data fetching is taken care of through the Main sensor
|
"""Show all data returned for this toner."""
|
||||||
|
return self.syncthru.toner_status().get(self._color, {})
|
||||||
|
|
||||||
if self.syncthru.is_online():
|
@property
|
||||||
self._attributes = self.syncthru.toner_status().get(self._color, {})
|
def state(self):
|
||||||
self._state = self._attributes.get("remaining")
|
"""Show amount of remaining toner."""
|
||||||
|
return self.syncthru.toner_status().get(self._color, {}).get("remaining")
|
||||||
|
|
||||||
|
|
||||||
class SyncThruDrumSensor(SyncThruSensor):
|
class SyncThruDrumSensor(SyncThruSensor):
|
||||||
|
@ -188,13 +198,15 @@ class SyncThruDrumSensor(SyncThruSensor):
|
||||||
self._unit_of_measurement = PERCENTAGE
|
self._unit_of_measurement = PERCENTAGE
|
||||||
self._id_suffix = f"_drum_{color}"
|
self._id_suffix = f"_drum_{color}"
|
||||||
|
|
||||||
def update(self):
|
@property
|
||||||
"""Get the latest data from SyncThru and update the state."""
|
def extra_state_attributes(self):
|
||||||
# Data fetching is taken care of through the Main sensor
|
"""Show all data returned for this drum."""
|
||||||
|
return self.syncthru.drum_status().get(self._color, {})
|
||||||
|
|
||||||
if self.syncthru.is_online():
|
@property
|
||||||
self._attributes = self.syncthru.drum_status().get(self._color, {})
|
def state(self):
|
||||||
self._state = self._attributes.get("remaining")
|
"""Show amount of remaining drum."""
|
||||||
|
return self.syncthru.drum_status().get(self._color, {}).get("remaining")
|
||||||
|
|
||||||
|
|
||||||
class SyncThruInputTraySensor(SyncThruSensor):
|
class SyncThruInputTraySensor(SyncThruSensor):
|
||||||
|
@ -207,15 +219,20 @@ class SyncThruInputTraySensor(SyncThruSensor):
|
||||||
self._number = number
|
self._number = number
|
||||||
self._id_suffix = f"_tray_{number}"
|
self._id_suffix = f"_tray_{number}"
|
||||||
|
|
||||||
def update(self):
|
@property
|
||||||
"""Get the latest data from SyncThru and update the state."""
|
def extra_state_attributes(self):
|
||||||
# Data fetching is taken care of through the Main sensor
|
"""Show all data returned for this input tray."""
|
||||||
|
return self.syncthru.input_tray_status().get(self._number, {})
|
||||||
|
|
||||||
if self.syncthru.is_online():
|
@property
|
||||||
self._attributes = self.syncthru.input_tray_status().get(self._number, {})
|
def state(self):
|
||||||
self._state = self._attributes.get("newError")
|
"""Display ready unless there is some error, then display error."""
|
||||||
if self._state == "":
|
tray_state = (
|
||||||
self._state = "Ready"
|
self.syncthru.input_tray_status().get(self._number, {}).get("newError")
|
||||||
|
)
|
||||||
|
if tray_state == "":
|
||||||
|
tray_state = "Ready"
|
||||||
|
return tray_state
|
||||||
|
|
||||||
|
|
||||||
class SyncThruOutputTraySensor(SyncThruSensor):
|
class SyncThruOutputTraySensor(SyncThruSensor):
|
||||||
|
@ -228,12 +245,17 @@ class SyncThruOutputTraySensor(SyncThruSensor):
|
||||||
self._number = number
|
self._number = number
|
||||||
self._id_suffix = f"_output_tray_{number}"
|
self._id_suffix = f"_output_tray_{number}"
|
||||||
|
|
||||||
def update(self):
|
@property
|
||||||
"""Get the latest data from SyncThru and update the state."""
|
def extra_state_attributes(self):
|
||||||
# Data fetching is taken care of through the Main sensor
|
"""Show all data returned for this output tray."""
|
||||||
|
return self.syncthru.output_tray_status().get(self._number, {})
|
||||||
|
|
||||||
if self.syncthru.is_online():
|
@property
|
||||||
self._attributes = self.syncthru.output_tray_status().get(self._number, {})
|
def state(self):
|
||||||
self._state = self._attributes.get("status")
|
"""Display ready unless there is some error, then display error."""
|
||||||
if self._state == "":
|
tray_state = (
|
||||||
self._state = "Ready"
|
self.syncthru.output_tray_status().get(self._number, {}).get("status")
|
||||||
|
)
|
||||||
|
if tray_state == "":
|
||||||
|
tray_state = "Ready"
|
||||||
|
return tray_state
|
||||||
|
|
|
@ -1756,7 +1756,7 @@ pystiebeleltron==0.0.1.dev2
|
||||||
pysuez==0.1.19
|
pysuez==0.1.19
|
||||||
|
|
||||||
# homeassistant.components.syncthru
|
# homeassistant.components.syncthru
|
||||||
pysyncthru==0.7.0
|
pysyncthru==0.7.3
|
||||||
|
|
||||||
# homeassistant.components.tankerkoenig
|
# homeassistant.components.tankerkoenig
|
||||||
pytankerkoenig==0.0.6
|
pytankerkoenig==0.0.6
|
||||||
|
|
|
@ -968,7 +968,7 @@ pyspcwebgw==0.4.0
|
||||||
pysqueezebox==0.5.5
|
pysqueezebox==0.5.5
|
||||||
|
|
||||||
# homeassistant.components.syncthru
|
# homeassistant.components.syncthru
|
||||||
pysyncthru==0.7.0
|
pysyncthru==0.7.3
|
||||||
|
|
||||||
# homeassistant.components.ecobee
|
# homeassistant.components.ecobee
|
||||||
python-ecobee-api==0.2.11
|
python-ecobee-api==0.2.11
|
||||||
|
|
Loading…
Add table
Reference in a new issue