Fixed zone test break and code style issues

This commit is contained in:
NMA 2016-08-25 21:33:07 +05:30
parent 95b7a8c4b9
commit 2ca3541eac
2 changed files with 21 additions and 17 deletions

View file

@ -12,7 +12,7 @@ from collections import defaultdict
import homeassistant.components.mqtt as mqtt
from homeassistant.const import STATE_HOME
from homeassistant.util import convert, slugify
from homeassistant.components import zone
from homeassistant.components import zone as zone_comp
DEPENDENCIES = ['mqtt']
@ -114,9 +114,9 @@ def setup_scanner(hass, config, see):
def enter_event():
"""Execute enter event."""
_zone = hass.states.get("zone.{}".format(location))
zone = hass.states.get("zone.{}".format(location))
with LOCK:
if _zone is None and data.get('t') == 'b':
if zone is None and data.get('t') == 'b':
# Not a HA zone, and a beacon so assume mobile
beacons = MOBILE_BEACONS_ACTIVE[dev_id]
if location not in beacons:
@ -128,7 +128,7 @@ def setup_scanner(hass, config, see):
if location not in regions:
regions.append(location)
_LOGGER.info("Enter region %s", location)
_set_gps_from_zone(kwargs, location, _zone)
_set_gps_from_zone(kwargs, location, zone)
see(**kwargs)
see_beacons(dev_id, kwargs)
@ -143,8 +143,8 @@ def setup_scanner(hass, config, see):
if new_region:
# Exit to previous region
_zone = hass.states.get("zone.{}".format(new_region))
_set_gps_from_zone(kwargs, new_region, _zone)
zone = hass.states.get("zone.{}".format(new_region))
_set_gps_from_zone(kwargs, new_region, zone)
_LOGGER.info("Exit to %s", new_region)
see(**kwargs)
see_beacons(dev_id, kwargs)
@ -201,7 +201,7 @@ def setup_scanner(hass, config, see):
lat = wayp['lat']
lon = wayp['lon']
rad = wayp['rad']
zone.add_zone(hass, name, lat, lon, rad)
zone_comp.add_zone(hass, name, lat, lon, rad)
def see_beacons(dev_id, kwargs_param):
"""Set active beacons to the current location."""
@ -240,12 +240,12 @@ def _parse_see_args(topic, data):
return dev_id, kwargs
def _set_gps_from_zone(kwargs, location, _zone):
def _set_gps_from_zone(kwargs, location, zone):
"""Set the see parameters from the zone parameters."""
if _zone is not None:
if zone is not None:
kwargs['gps'] = (
_zone.attributes['latitude'],
_zone.attributes['longitude'])
kwargs['gps_accuracy'] = _zone.attributes['radius']
zone.attributes['latitude'],
zone.attributes['longitude'])
kwargs['gps_accuracy'] = zone.attributes['radius']
kwargs['location_name'] = location
return kwargs

View file

@ -73,7 +73,7 @@ def in_zone(zone, latitude, longitude, radius=0):
def setup(hass, config):
"""Setup zone."""
entities = set()
for key in extract_domain_configs(config, DOMAIN):
entries = config[key]
if not isinstance(entries, list):
@ -92,7 +92,8 @@ def setup(hass, config):
'Each zone needs a latitude and longitude.')
continue
zone = Zone(hass, name, latitude, longitude, radius, icon, passive, False)
zone = Zone(hass, name, latitude, longitude, radius, icon,
passive, False)
zone.entity_id = generate_entity_id(ENTITY_ID_FORMAT, name,
entities)
zone.update_ha_state()
@ -100,7 +101,8 @@ def setup(hass, config):
if ENTITY_ID_HOME not in entities:
zone = Zone(hass, hass.config.location_name, hass.config.latitude,
hass.config.longitude, DEFAULT_RADIUS, ICON_HOME, False, False)
hass.config.longitude, DEFAULT_RADIUS, ICON_HOME,
False, False)
zone.entity_id = ENTITY_ID_HOME
zone.update_ha_state()
@ -108,12 +110,13 @@ def setup(hass, config):
# Add a zone to the existing set
def add_zone(hass, name, latitude, longitude, radius):
"""Add a zone from other components"""
_LOGGER.info("Adding new zone %s", name)
if name not in entities:
zone = Zone(hass, name, latitude, longitude, radius, ICON_IMPORT,
False, True)
zone.entity_id = generate_entity_id(ENTITY_ID_FORMAT, name,
entities)
entities)
zone.update_ha_state()
entities.add(zone.entity_id)
else:
@ -123,7 +126,8 @@ class Zone(Entity):
"""Representation of a Zone."""
# pylint: disable=too-many-arguments, too-many-instance-attributes
def __init__(self, hass, name, latitude, longitude, radius, icon, passive, imported):
def __init__(self, hass, name, latitude, longitude, radius, icon, passive,
imported):
"""Initialize the zone."""
self.hass = hass
self._name = name