Adding a discoverable Samsung Syncthru Printer sensor platform#13134
Adding a discoverable Samsung Syncthru Printer sensor platform#13134balloob merged 56 commits intohome-assistant:devfrom
Conversation
|
Successor of #12529. |
fabaff
left a comment
There was a problem hiding this comment.
Also, nielstron/pysyncthru#1 needs to be addressed.
| devices = [SyncThruMain(hass, printer, name)] | ||
|
|
||
| for key in printer.tonerStatus(filter_supported=True): | ||
| if 'toner_' + str(key) in monitored: |
| monitored = config.get(CONF_MONITORED_CONDITIONS) | ||
|
|
||
| # Main device, always added | ||
| printer = SyncThru(host) |
There was a problem hiding this comment.
You need to catch the TypeError here.
|
|
||
| def __init__(self, hass, syncthru, name): | ||
| """Initialize the sensor.""" | ||
| self._hass = hass |
| self._hass = hass | ||
| self.syncthru = syncthru | ||
| self._attributes = {} | ||
| self._state = STATE_UNKNOWN |
There was a problem hiding this comment.
Set the state to None and let HA handle unknown states.
| @@ -0,0 +1,244 @@ | |||
| """Connect to a Samsung Printer via SyncThru web interface.""" | |||
There was a problem hiding this comment.
Please align he style of the file header with the other platforms.
| devices.append(SyncThruOutputTray(hass, printer, name, key)) | ||
|
|
||
| add_devices(devices, True) | ||
| return True |
|
|
||
|
|
||
| class SyncThruMain(SyncThruSensor): | ||
| """Implementaion of the main sensor, monitoring the general state.""" |
| # Test if the discovered device actually is a syncthru printer | ||
| if not test_syncthru(host): | ||
| _LOGGER.error("No SyncThru Printer found at %s", host) | ||
| return False |
| @property | ||
| def device_state_attributes(self): | ||
| """Return the state attributes of the device.""" | ||
| self._attributes[CONF_FRIENDLY_NAME] = self._friendly_name |
There was a problem hiding this comment.
Friendly name is only for users to set. Platforms can set the name property. If platform wants to have different default friendly name from entity_id, the platform sets the entity_id too.
| self._attributes = {} | ||
| self._state = STATE_UNKNOWN | ||
| self._name = name | ||
| self._friendly_name = name |
| self._state = self.syncthru.deviceStatus() | ||
|
|
||
| if self.syncthru.isOnline(): | ||
| self._friendly_name = self.syncthru.model() |
There was a problem hiding this comment.
See above about friendly name.
| self._attributes = self.syncthru.tonerStatus( | ||
| ).get(self._color, {}) | ||
| self._state = self._attributes.get( | ||
| 'remaining', STATE_UNKNOWN) |
There was a problem hiding this comment.
Don't use STATE_UNKNOWN. Use None, which is the default value returned if key is missing in the dict.
There was a problem hiding this comment.
'homeassistant.const.CONF_FRIENDLY_NAME' imported but unused
There was a problem hiding this comment.
Please limit this to the exception you expect.
There was a problem hiding this comment.
Don't pass in hass. It will be set on the entity when it has been added to home assistant.
There was a problem hiding this comment.
Should this be removed? It's called below too if the printer is online.
There was a problem hiding this comment.
expected 2 blank lines after class or function definition, found 0
missing whitespace around operator
missing whitespace after ':'
There was a problem hiding this comment.
expected 2 blank lines after class or function definition, found 0
missing whitespace around operator
There was a problem hiding this comment.
expected 2 blank lines after class or function definition, found 0
IndentationError: unexpected unindent
missing whitespace around bitwise or shift operator
missing whitespace around operator
There was a problem hiding this comment.
IndentationError: unindent does not match any outer indentation level
|
Please rebase this |
Adds a component based on pyblnet, that hooks up the blnet to home assistant
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.
|
@nielstron is this ready to merge? |
|
Yes this is ready for merging on my opinion. The home-assistant.io PR has no logo but I doubt it will be allowed by Samsung to use their logo. could also be added in a later request.
|
.coveragerc
Outdated
| homeassistant/components/sensor/pushbullet.py | ||
| homeassistant/components/sensor/pvoutput.py | ||
| homeassistant/components/sensor/pyload.py | ||
| homeassistant/components/sensor/syncthru.py |
|
Can be merged when build passes. |
|
I have added my printer with this component using the hostname however the discovery adds a second device with the ip address. Should I fill an issue for that or is this inherent to the discovery stuff? |
Description:
Pull request in netdisco: home-assistant-libs/netdisco#174
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4707
Example entry for
configuration.yaml(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.