mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Fixed zone test break and code style issues
This commit is contained in:
parent
95b7a8c4b9
commit
2ca3541eac
@ -12,7 +12,7 @@ from collections import defaultdict
|
|||||||
import homeassistant.components.mqtt as mqtt
|
import homeassistant.components.mqtt as mqtt
|
||||||
from homeassistant.const import STATE_HOME
|
from homeassistant.const import STATE_HOME
|
||||||
from homeassistant.util import convert, slugify
|
from homeassistant.util import convert, slugify
|
||||||
from homeassistant.components import zone
|
from homeassistant.components import zone as zone_comp
|
||||||
|
|
||||||
DEPENDENCIES = ['mqtt']
|
DEPENDENCIES = ['mqtt']
|
||||||
|
|
||||||
@ -114,9 +114,9 @@ def setup_scanner(hass, config, see):
|
|||||||
|
|
||||||
def enter_event():
|
def enter_event():
|
||||||
"""Execute enter event."""
|
"""Execute enter event."""
|
||||||
_zone = hass.states.get("zone.{}".format(location))
|
zone = hass.states.get("zone.{}".format(location))
|
||||||
with LOCK:
|
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
|
# Not a HA zone, and a beacon so assume mobile
|
||||||
beacons = MOBILE_BEACONS_ACTIVE[dev_id]
|
beacons = MOBILE_BEACONS_ACTIVE[dev_id]
|
||||||
if location not in beacons:
|
if location not in beacons:
|
||||||
@ -128,7 +128,7 @@ def setup_scanner(hass, config, see):
|
|||||||
if location not in regions:
|
if location not in regions:
|
||||||
regions.append(location)
|
regions.append(location)
|
||||||
_LOGGER.info("Enter region %s", location)
|
_LOGGER.info("Enter region %s", location)
|
||||||
_set_gps_from_zone(kwargs, location, _zone)
|
_set_gps_from_zone(kwargs, location, zone)
|
||||||
|
|
||||||
see(**kwargs)
|
see(**kwargs)
|
||||||
see_beacons(dev_id, kwargs)
|
see_beacons(dev_id, kwargs)
|
||||||
@ -143,8 +143,8 @@ def setup_scanner(hass, config, see):
|
|||||||
|
|
||||||
if new_region:
|
if new_region:
|
||||||
# Exit to previous region
|
# Exit to previous region
|
||||||
_zone = hass.states.get("zone.{}".format(new_region))
|
zone = hass.states.get("zone.{}".format(new_region))
|
||||||
_set_gps_from_zone(kwargs, new_region, _zone)
|
_set_gps_from_zone(kwargs, new_region, zone)
|
||||||
_LOGGER.info("Exit to %s", new_region)
|
_LOGGER.info("Exit to %s", new_region)
|
||||||
see(**kwargs)
|
see(**kwargs)
|
||||||
see_beacons(dev_id, kwargs)
|
see_beacons(dev_id, kwargs)
|
||||||
@ -201,7 +201,7 @@ def setup_scanner(hass, config, see):
|
|||||||
lat = wayp['lat']
|
lat = wayp['lat']
|
||||||
lon = wayp['lon']
|
lon = wayp['lon']
|
||||||
rad = wayp['rad']
|
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):
|
def see_beacons(dev_id, kwargs_param):
|
||||||
"""Set active beacons to the current location."""
|
"""Set active beacons to the current location."""
|
||||||
@ -240,12 +240,12 @@ def _parse_see_args(topic, data):
|
|||||||
return dev_id, kwargs
|
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."""
|
"""Set the see parameters from the zone parameters."""
|
||||||
if _zone is not None:
|
if zone is not None:
|
||||||
kwargs['gps'] = (
|
kwargs['gps'] = (
|
||||||
_zone.attributes['latitude'],
|
zone.attributes['latitude'],
|
||||||
_zone.attributes['longitude'])
|
zone.attributes['longitude'])
|
||||||
kwargs['gps_accuracy'] = _zone.attributes['radius']
|
kwargs['gps_accuracy'] = zone.attributes['radius']
|
||||||
kwargs['location_name'] = location
|
kwargs['location_name'] = location
|
||||||
return kwargs
|
return kwargs
|
||||||
|
@ -73,7 +73,7 @@ def in_zone(zone, latitude, longitude, radius=0):
|
|||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
"""Setup zone."""
|
"""Setup zone."""
|
||||||
|
entities = set()
|
||||||
for key in extract_domain_configs(config, DOMAIN):
|
for key in extract_domain_configs(config, DOMAIN):
|
||||||
entries = config[key]
|
entries = config[key]
|
||||||
if not isinstance(entries, list):
|
if not isinstance(entries, list):
|
||||||
@ -92,7 +92,8 @@ def setup(hass, config):
|
|||||||
'Each zone needs a latitude and longitude.')
|
'Each zone needs a latitude and longitude.')
|
||||||
continue
|
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,
|
zone.entity_id = generate_entity_id(ENTITY_ID_FORMAT, name,
|
||||||
entities)
|
entities)
|
||||||
zone.update_ha_state()
|
zone.update_ha_state()
|
||||||
@ -100,7 +101,8 @@ def setup(hass, config):
|
|||||||
|
|
||||||
if ENTITY_ID_HOME not in entities:
|
if ENTITY_ID_HOME not in entities:
|
||||||
zone = Zone(hass, hass.config.location_name, hass.config.latitude,
|
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.entity_id = ENTITY_ID_HOME
|
||||||
zone.update_ha_state()
|
zone.update_ha_state()
|
||||||
|
|
||||||
@ -108,12 +110,13 @@ def setup(hass, config):
|
|||||||
|
|
||||||
# Add a zone to the existing set
|
# Add a zone to the existing set
|
||||||
def add_zone(hass, name, latitude, longitude, radius):
|
def add_zone(hass, name, latitude, longitude, radius):
|
||||||
|
"""Add a zone from other components"""
|
||||||
_LOGGER.info("Adding new zone %s", name)
|
_LOGGER.info("Adding new zone %s", name)
|
||||||
if name not in entities:
|
if name not in entities:
|
||||||
zone = Zone(hass, name, latitude, longitude, radius, ICON_IMPORT,
|
zone = Zone(hass, name, latitude, longitude, radius, ICON_IMPORT,
|
||||||
False, True)
|
False, True)
|
||||||
zone.entity_id = generate_entity_id(ENTITY_ID_FORMAT, name,
|
zone.entity_id = generate_entity_id(ENTITY_ID_FORMAT, name,
|
||||||
entities)
|
entities)
|
||||||
zone.update_ha_state()
|
zone.update_ha_state()
|
||||||
entities.add(zone.entity_id)
|
entities.add(zone.entity_id)
|
||||||
else:
|
else:
|
||||||
@ -123,7 +126,8 @@ class Zone(Entity):
|
|||||||
"""Representation of a Zone."""
|
"""Representation of a Zone."""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments, too-many-instance-attributes
|
# 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."""
|
"""Initialize the zone."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self._name = name
|
self._name = name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user