Skip to content

Adding a discoverable Samsung Syncthru Printer sensor platform#13134

Merged
balloob merged 56 commits intohome-assistant:devfrom
nielstron:pysyncthru
Mar 18, 2018
Merged

Adding a discoverable Samsung Syncthru Printer sensor platform#13134
balloob merged 56 commits intohome-assistant:devfrom
nielstron:pysyncthru

Conversation

@nielstron
Copy link
Copy Markdown
Contributor

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):

  - platform: syncthru
    resource: http://my.printer.address
    monitored_conditions:
        - toner_black

Checklist:

  • The code change is tested and works locally.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

@nielstron nielstron requested a review from andrey-git as a code owner March 12, 2018 16:40
@nielstron nielstron changed the title Adding a discoverable Samsung Syncthru Printer component Adding a discoverable Samsung Syncthru Printer sensor platform Mar 12, 2018
@fabaff
Copy link
Copy Markdown
Member

fabaff commented Mar 12, 2018

Successor of #12529.

Copy link
Copy Markdown
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use string formatting.

monitored = config.get(CONF_MONITORED_CONDITIONS)

# Main device, always added
printer = SyncThru(host)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to catch the TypeError here.


def __init__(self, hass, syncthru, name):
"""Initialize the sensor."""
self._hass = hass
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used.

self._hass = hass
self.syncthru = syncthru
self._attributes = {}
self._state = STATE_UNKNOWN
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the state to None and let HA handle unknown states.

@@ -0,0 +1,244 @@
"""Connect to a Samsung Printer via SyncThru web interface."""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed.



class SyncThruMain(SyncThruSensor):
"""Implementaion of the main sensor, monitoring the general state."""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: Implementaion

# 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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return.

@property
def device_state_attributes(self):
"""Return the state attributes of the device."""
self._attributes[CONF_FRIENDLY_NAME] = self._friendly_name
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

self._state = self.syncthru.deviceStatus()

if self.syncthru.isOnline():
self._friendly_name = self.syncthru.model()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above about friendly name.

self._attributes = self.syncthru.tonerStatus(
).get(self._color, {})
self._state = self._attributes.get(
'remaining', STATE_UNKNOWN)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use STATE_UNKNOWN. Use None, which is the default value returned if key is missing in the dict.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many blank lines (2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many blank lines (3)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'homeassistant.const.CONF_FRIENDLY_NAME' imported but unused

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please limit this to the exception you expect.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary return.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't pass in hass. It will be set on the entity when it has been added to home assistant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output tray sensor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drum sensor.

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed? It's called below too if the printer is online.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected indentation

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines after class or function definition, found 0
missing whitespace around operator
missing whitespace after ':'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected indentation

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines after class or function definition, found 0
missing whitespace around operator

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected indentation

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IndentationError: unindent does not match any outer indentation level

@cdce8p cdce8p removed their request for review March 15, 2018 12:09
@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented Mar 17, 2018

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.
@MartinHjelmare
Copy link
Copy Markdown
Member

@nielstron is this ready to merge?

@nielstron
Copy link
Copy Markdown
Contributor Author

nielstron commented Mar 17, 2018 via email

.coveragerc Outdated
homeassistant/components/sensor/pushbullet.py
homeassistant/components/sensor/pvoutput.py
homeassistant/components/sensor/pyload.py
homeassistant/components/sensor/syncthru.py
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sort 🔤.

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MartinHjelmare
Copy link
Copy Markdown
Member

Can be merged when build passes.

@balloob balloob merged commit 6b05948 into home-assistant:dev Mar 18, 2018
@balloob balloob mentioned this pull request Mar 30, 2018
@Diaoul
Copy link
Copy Markdown
Contributor

Diaoul commented Apr 9, 2018

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?

@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants