Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions homeassistant/components/sensor/qnap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from homeassistant.helpers.entity import Entity
from homeassistant.const import (
CONF_HOST, CONF_USERNAME, CONF_PASSWORD, CONF_PORT, CONF_SSL, ATTR_NAME,
CONF_VERIFY_SSL, CONF_TIMEOUT, CONF_MONITORED_CONDITIONS, TEMP_CELSIUS)
CONF_VERIFY_SSL, CONF_TIMEOUT, CONF_MONITORED_CONDITIONS, TEMP_CELSIUS,
CONF_ALLOW_UNREACHABLE)
from homeassistant.util import Throttle
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['qnapstats==0.2.7']
Expand Down Expand Up @@ -99,6 +101,7 @@
vol.Optional(CONF_NICS): cv.ensure_list,
vol.Optional(CONF_DRIVES): cv.ensure_list,
vol.Optional(CONF_VOLUMES): cv.ensure_list,
vol.Optional(CONF_ALLOW_UNREACHABLE, default=False): cv.boolean,

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.

Why you make that as option?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hi, the reasoning is that if this setting is False (the default), this sensor keeps its old behaviour. This is for people who have their NAS on 24/7 and want to see the notification. Setting it to True hides the notification and uses the HA PlatformNotReady mechanism.

BUT: maybe this option should dissapear and the PlatformNotReady should become the default, ditching the notification, that's another option and I'm open to opinions on 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.

It should be only PlatformNotReady and the should be covered/handled by available(). Adding an option to configure the behavior of the notification looks wired .

@mrosseel mrosseel Sep 6, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi, ok If I understand correctly you would just drop the config option and the notification, and use PlatformNotReady as the only behaviour. Sounds good, I'll remove the config + notification. Anything else that needs to be changed? Not familiar with "available()".

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.

Available property is simple: return False if the the device is not reachable (maybe the state fetch going wrong on update) and True if they is back.

})


Expand All @@ -107,13 +110,18 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
api = QNAPStatsAPI(config)
api.update()

# QNAP is not available
if not api.data:
hass.components.persistent_notification.create(
'Error: Failed to set up QNAP sensor.<br />'
'Check the logs for additional information. '
'You will need to restart hass after fixing.',
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID)
# the user is ok with qnap being not available, setup will be retried
if config.get(CONF_ALLOW_UNREACHABLE):
raise PlatformNotReady
else:
hass.components.persistent_notification.create(
'Error: Failed to set up QNAP sensor.<br />'
'Check the logs for additional information. '
'You will need to restart hass after fixing.',
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID)
return False

sensors = []
Expand Down
1 change: 1 addition & 0 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
CONF_ACCESS_TOKEN = 'access_token'
CONF_ADDRESS = 'address'
CONF_AFTER = 'after'
CONF_ALLOW_UNREACHABLE = 'allow_unreachable'
CONF_ALIAS = 'alias'
CONF_API_KEY = 'api_key'
CONF_API_VERSION = 'api_version'
Expand Down