core/homeassistant/components/syncthru/sensor.py

241 lines
8.1 KiB
Python
Raw Normal View History

"""Support for Samsung Printers with SyncThru web interface."""
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
import logging
from pysyncthru import SYNCTHRU_STATE_HUMAN, SyncThru
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.const import CONF_NAME, CONF_RESOURCE, CONF_URL, PERCENTAGE
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
from . import device_identifiers
from .const import DEFAULT_MODEL, DEFAULT_NAME_TEMPLATE, DOMAIN
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
_LOGGER = logging.getLogger(__name__)
2019-07-31 19:25:30 +00:00
COLORS = ["black", "cyan", "magenta", "yellow"]
DRUM_COLORS = COLORS
TONER_COLORS = COLORS
TRAYS = range(1, 6)
OUTPUT_TRAYS = range(0, 6)
DEFAULT_MONITORED_CONDITIONS = []
DEFAULT_MONITORED_CONDITIONS.extend([f"toner_{key}" for key in TONER_COLORS])
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"output_tray_{key}" for key in OUTPUT_TRAYS])
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
2019-07-31 19:25:30 +00:00
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_RESOURCE): cv.url,
vol.Optional(
CONF_NAME, default=DEFAULT_NAME_TEMPLATE.format(DEFAULT_MODEL)
): cv.string,
2019-07-31 19:25:30 +00:00
}
)
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
2019-07-31 19:25:30 +00:00
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
"""Set up the SyncThru component."""
_LOGGER.warning(
"Loading syncthru via platform config is deprecated and no longer "
"necessary as of 0.113. Please remove it from your configuration YAML."
)
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_URL: config.get(CONF_RESOURCE),
CONF_NAME: config.get(CONF_NAME),
},
2019-07-31 19:25:30 +00:00
)
)
return True
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up from config entry."""
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
printer = hass.data[DOMAIN][config_entry.entry_id]
supp_toner = printer.toner_status(filter_supported=True)
supp_drum = printer.drum_status(filter_supported=True)
supp_tray = printer.input_tray_status(filter_supported=True)
supp_output_tray = printer.output_tray_status()
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
name = config_entry.data[CONF_NAME]
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
devices = [SyncThruMainSensor(printer, name)]
for key in supp_toner:
devices.append(SyncThruTonerSensor(printer, name, key))
for key in supp_drum:
devices.append(SyncThruDrumSensor(printer, name, key))
for key in supp_tray:
devices.append(SyncThruInputTraySensor(printer, name, key))
for key in supp_output_tray:
devices.append(SyncThruOutputTraySensor(printer, name, key))
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
async_add_entities(devices, True)
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
class SyncThruSensor(Entity):
"""Implementation of an abstract Samsung Printer sensor platform."""
def __init__(self, syncthru, name):
"""Initialize the sensor."""
self.syncthru: SyncThru = syncthru
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
self._attributes = {}
self._state = None
self._name = name
2019-07-31 19:25:30 +00:00
self._icon = "mdi:printer"
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
self._unit_of_measurement = None
2019-07-31 19:25:30 +00:00
self._id_suffix = ""
@property
def unique_id(self):
"""Return unique ID for the sensor."""
serial = self.syncthru.serial_number()
return serial + self._id_suffix if serial else super().unique_id
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
@property
def name(self):
"""Return the name of the sensor."""
return self._name
@property
def state(self):
"""Return the state of the device."""
return self._state
@property
def icon(self):
"""Return the icon of the device."""
return self._icon
@property
def unit_of_measurement(self):
"""Return the unit of measuremnt."""
return self._unit_of_measurement
@property
def device_state_attributes(self):
"""Return the state attributes of the device."""
return self._attributes
@property
def device_info(self):
"""Return device information."""
return {"identifiers": device_identifiers(self.syncthru)}
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
class SyncThruMainSensor(SyncThruSensor):
"""Implementation of the main sensor, conducting the actual polling."""
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
def __init__(self, syncthru, name):
"""Initialize the sensor."""
super().__init__(syncthru, name)
2019-07-31 19:25:30 +00:00
self._id_suffix = "_main"
self._active = True
async def async_update(self):
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
"""Get the latest data from SyncThru and update the state."""
if not self._active:
return
try:
await self.syncthru.update()
except ValueError:
# if an exception is thrown, printer does not support syncthru
_LOGGER.warning(
"Configured printer at %s does not support SyncThru. "
"Consider changing your configuration",
2019-07-31 19:25:30 +00:00
self.syncthru.url,
)
self._active = False
self._state = SYNCTHRU_STATE_HUMAN[self.syncthru.device_status()]
self._attributes = {"display_text": self.syncthru.device_status_details()}
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
class SyncThruTonerSensor(SyncThruSensor):
"""Implementation of a Samsung Printer toner sensor platform."""
def __init__(self, syncthru, name, color):
"""Initialize the sensor."""
super().__init__(syncthru, name)
self._name = f"{name} Toner {color}"
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
self._color = color
self._unit_of_measurement = PERCENTAGE
self._id_suffix = f"_toner_{color}"
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
def update(self):
"""Get the latest data from SyncThru and update the state."""
# Data fetching is taken care of through the Main sensor
if self.syncthru.is_online():
2019-07-31 19:25:30 +00:00
self._attributes = self.syncthru.toner_status().get(self._color, {})
self._state = self._attributes.get("remaining")
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
class SyncThruDrumSensor(SyncThruSensor):
"""Implementation of a Samsung Printer toner sensor platform."""
def __init__(self, syncthru, name, color):
"""Initialize the sensor."""
super().__init__(syncthru, name)
self._name = f"{name} Drum {color}"
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
self._color = color
self._unit_of_measurement = PERCENTAGE
self._id_suffix = f"_drum_{color}"
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
def update(self):
"""Get the latest data from SyncThru and update the state."""
# Data fetching is taken care of through the Main sensor
if self.syncthru.is_online():
2019-07-31 19:25:30 +00:00
self._attributes = self.syncthru.drum_status().get(self._color, {})
self._state = self._attributes.get("remaining")
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
class SyncThruInputTraySensor(SyncThruSensor):
"""Implementation of a Samsung Printer input tray sensor platform."""
def __init__(self, syncthru, name, number):
"""Initialize the sensor."""
super().__init__(syncthru, name)
self._name = f"{name} Tray {number}"
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
self._number = number
self._id_suffix = f"_tray_{number}"
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
def update(self):
"""Get the latest data from SyncThru and update the state."""
# Data fetching is taken care of through the Main sensor
if self.syncthru.is_online():
2019-07-31 19:25:30 +00:00
self._attributes = self.syncthru.input_tray_status().get(self._number, {})
self._state = self._attributes.get("newError")
if self._state == "":
self._state = "Ready"
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
class SyncThruOutputTraySensor(SyncThruSensor):
"""Implementation of a Samsung Printer input tray sensor platform."""
def __init__(self, syncthru, name, number):
"""Initialize the sensor."""
super().__init__(syncthru, name)
self._name = f"{name} Output Tray {number}"
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
self._number = number
self._id_suffix = f"_output_tray_{number}"
Adding a discoverable Samsung Syncthru Printer sensor platform (#13134) * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Changed to Dependencis, import inside setup_platform * Switch back to REQUIREMENTS Looks like DEPENDENCIES is not meant for python packages but for other HA components * Fixed access to _attributes * Final fix * Several Bugfixes When the printer goes offline, the last state will be kept. Also now checks if the printer is reachable upon setup * Register syncthru as discoverable * Included possible conditions to monitor * Split the printer sensor in several seperate sensor entities * Fixed bug at sensor creation, pep8 conform * Bugfix * Bugfix * Removed Blnet components * Fixed unused import * Renamed discoverable to samsung_printer * Removed unused Attribute _friendly_name * Inserted missing space * Pinned requirements and added to coveragerc * Reduced redundancy by condensing into multiple sub-classes * Fixed indentation * Fixed super constructor calls * Fixed super constructor calls * Fixed format * Resolving style issues and using name instead of friendly_name * Pinned pysyncthru in requirements_all, having trouble with friendly_name * Iterating over dictionary instead of dict.keys() * ran gen_reqirements_all.py * Fixed flake 8 issues * Added a simple component to support the BLNET Adds a component based on pyblnet, that hooks up the blnet to home assistant * Implemented requested changes * raised dependecies to pysyncthru version that has timeouts * Raised required version for full timeout support * Adds support for custimzation of blnet sensor devices * Setting up blnet as a platfrom * Updated use of state_attributes Now the friendly_name (and for digital values the mode) is set in the state_attributes whereas the name is defined as "blnet_(analog|digital)_{sensornumber}" so you can reliably add them to groups. * Added support for the SyncThru printer web service * Added pysyncthru to the requirements * Removed Blnet components * Pinned requirements and added to coveragerc * Fixed indentation * Fixed format * Pinned pysyncthru in requirements_all, having trouble with friendly_name * ran gen_reqirements_all.py * Updated requirements_all * Renamed sensor objects, removed passing of hass entity * Removed merge artifacts * Reset syncthru to newest state * Updated requirements_all * switched to using the newest version of pysyncthru * Sorted coveragerc
2018-03-18 16:26:33 +00:00
def update(self):
"""Get the latest data from SyncThru and update the state."""
# Data fetching is taken care of through the Main sensor
if self.syncthru.is_online():
2019-07-31 19:25:30 +00:00
self._attributes = self.syncthru.output_tray_status().get(self._number, {})
self._state = self._attributes.get("status")
if self._state == "":
self._state = "Ready"