Skip to content

Commit

Permalink
Use hass.data dict instead GLOBALS
Browse files Browse the repository at this point in the history
  • Loading branch information
tchellomello committed Mar 25, 2017
1 parent e381158 commit e61015a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
5 changes: 2 additions & 3 deletions homeassistant/components/binary_sensor/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from homeassistant.components.ring import (
CONF_ATTRIBUTION, DEFAULT_ENTITY_NAMESPACE, DEFAULT_CACHEDB)

from homeassistant.loader import get_component
from homeassistant.components.binary_sensor import (
BinarySensorDevice, PLATFORM_SCHEMA)
from homeassistant.const import (
Expand All @@ -38,11 +37,11 @@

def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up a sensor for a Ring device."""
ring = get_component('ring')
ring = hass.data.get('ring')

sensors = []
for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
for device in ring.RING.data.doorbells:
for device in ring.doorbells:
if 'doorbell' in SENSOR_TYPES[sensor_type][1]:
sensors.append(RingBinarySensor(hass,
device,
Expand Down
13 changes: 1 addition & 12 deletions homeassistant/components/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
DEFAULT_SCAN_INTERVAL = timedelta(seconds=30)
SCAN_INTERVAL = timedelta(seconds=5)

RING = None

CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_USERNAME): cv.string,
Expand All @@ -42,7 +40,6 @@

def setup(hass, config):
"""Set up Ring component."""
global RING
conf = config[DOMAIN]
username = conf.get(CONF_USERNAME)
password = conf.get(CONF_PASSWORD)
Expand All @@ -53,7 +50,7 @@ def setup(hass, config):

ring = Ring(username, password)
if ring.is_connected:
RING = RingData(ring)
hass.data['ring'] = ring
except (ConnectTimeout, HTTPError) as ex:
_LOGGER.error("Unable to connect to Ring service: %s", str(ex))
persistent_notification.create(
Expand All @@ -64,11 +61,3 @@ def setup(hass, config):
notification_id=NOTIFICATION_ID)
return False
return True


class RingData(object):
"""Stores the data retrived for Ring device."""

def __init__(self, data):
"""Initialize the data object."""
self.data = data
7 changes: 3 additions & 4 deletions homeassistant/components/sensor/ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS, CONF_SCAN_INTERVAL,
STATE_UNKNOWN, ATTR_ATTRIBUTION)

from homeassistant.loader import get_component
from homeassistant.helpers.entity import Entity

DEPENDENCIES = ['ring']
Expand Down Expand Up @@ -45,17 +44,17 @@

def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up a sensor for a Ring device."""
ring = get_component('ring')
ring = hass.data.get('ring')

sensors = []
for sensor_type in config.get(CONF_MONITORED_CONDITIONS):
for device in ring.RING.data.chimes:
for device in ring.chimes:
if 'chime' in SENSOR_TYPES[sensor_type][1]:
sensors.append(RingSensor(hass,
device,
sensor_type))

for device in ring.RING.data.doorbells:
for device in ring.doorbells:
if 'doorbell' in SENSOR_TYPES[sensor_type][1]:
sensors.append(RingSensor(hass,
device,
Expand Down

0 comments on commit e61015a

Please sign in to comment.