Move imports to top for spc (#29547)
* Move imports to top for spc * Fix pylint error by removing duplicate importpull/29570/head
parent
d9b52ef98c
commit
606d310ea3
|
@ -1,11 +1,14 @@
|
||||||
"""Support for Vanderbilt (formerly Siemens) SPC alarm systems."""
|
"""Support for Vanderbilt (formerly Siemens) SPC alarm systems."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pyspcwebgw import SpcWebGateway
|
||||||
|
from pyspcwebgw.area import Area
|
||||||
|
from pyspcwebgw.zone import Zone
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.helpers import discovery, aiohttp_client
|
from homeassistant.helpers import aiohttp_client, discovery
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -33,11 +36,8 @@ CONFIG_SCHEMA = vol.Schema(
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up the SPC component."""
|
"""Set up the SPC component."""
|
||||||
from pyspcwebgw import SpcWebGateway
|
|
||||||
|
|
||||||
async def async_upate_callback(spc_object):
|
async def async_upate_callback(spc_object):
|
||||||
from pyspcwebgw.area import Area
|
|
||||||
from pyspcwebgw.zone import Zone
|
|
||||||
|
|
||||||
if isinstance(spc_object, Area):
|
if isinstance(spc_object, Area):
|
||||||
async_dispatcher_send(hass, SIGNAL_UPDATE_ALARM.format(spc_object.id))
|
async_dispatcher_send(hass, SIGNAL_UPDATE_ALARM.format(spc_object.id))
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
"""Support for Vanderbilt (formerly Siemens) SPC alarm systems."""
|
"""Support for Vanderbilt (formerly Siemens) SPC alarm systems."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pyspcwebgw.const import AreaMode
|
||||||
|
|
||||||
import homeassistant.components.alarm_control_panel as alarm
|
import homeassistant.components.alarm_control_panel as alarm
|
||||||
from homeassistant.components.alarm_control_panel.const import (
|
from homeassistant.components.alarm_control_panel.const import (
|
||||||
SUPPORT_ALARM_ARM_AWAY,
|
SUPPORT_ALARM_ARM_AWAY,
|
||||||
|
@ -24,7 +26,6 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
def _get_alarm_state(area):
|
def _get_alarm_state(area):
|
||||||
"""Get the alarm state."""
|
"""Get the alarm state."""
|
||||||
from pyspcwebgw.const import AreaMode
|
|
||||||
|
|
||||||
if area.verified_alarm:
|
if area.verified_alarm:
|
||||||
return STATE_ALARM_TRIGGERED
|
return STATE_ALARM_TRIGGERED
|
||||||
|
@ -92,24 +93,20 @@ class SpcAlarm(alarm.AlarmControlPanel):
|
||||||
|
|
||||||
async def async_alarm_disarm(self, code=None):
|
async def async_alarm_disarm(self, code=None):
|
||||||
"""Send disarm command."""
|
"""Send disarm command."""
|
||||||
from pyspcwebgw.const import AreaMode
|
|
||||||
|
|
||||||
await self._api.change_mode(area=self._area, new_mode=AreaMode.UNSET)
|
await self._api.change_mode(area=self._area, new_mode=AreaMode.UNSET)
|
||||||
|
|
||||||
async def async_alarm_arm_home(self, code=None):
|
async def async_alarm_arm_home(self, code=None):
|
||||||
"""Send arm home command."""
|
"""Send arm home command."""
|
||||||
from pyspcwebgw.const import AreaMode
|
|
||||||
|
|
||||||
await self._api.change_mode(area=self._area, new_mode=AreaMode.PART_SET_A)
|
await self._api.change_mode(area=self._area, new_mode=AreaMode.PART_SET_A)
|
||||||
|
|
||||||
async def async_alarm_arm_night(self, code=None):
|
async def async_alarm_arm_night(self, code=None):
|
||||||
"""Send arm home command."""
|
"""Send arm home command."""
|
||||||
from pyspcwebgw.const import AreaMode
|
|
||||||
|
|
||||||
await self._api.change_mode(area=self._area, new_mode=AreaMode.PART_SET_B)
|
await self._api.change_mode(area=self._area, new_mode=AreaMode.PART_SET_B)
|
||||||
|
|
||||||
async def async_alarm_arm_away(self, code=None):
|
async def async_alarm_arm_away(self, code=None):
|
||||||
"""Send arm away command."""
|
"""Send arm away command."""
|
||||||
from pyspcwebgw.const import AreaMode
|
|
||||||
|
|
||||||
await self._api.change_mode(area=self._area, new_mode=AreaMode.FULL_SET)
|
await self._api.change_mode(area=self._area, new_mode=AreaMode.FULL_SET)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
"""Support for Vanderbilt (formerly Siemens) SPC alarm systems."""
|
"""Support for Vanderbilt (formerly Siemens) SPC alarm systems."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pyspcwebgw.const import ZoneInput
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
@ -60,7 +62,6 @@ class SpcBinarySensor(BinarySensorDevice):
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Whether the device is switched on."""
|
"""Whether the device is switched on."""
|
||||||
from pyspcwebgw.const import ZoneInput
|
|
||||||
|
|
||||||
return self._zone.input == ZoneInput.OPEN
|
return self._zone.input == ZoneInput.OPEN
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ async def test_valid_device_config(hass, monkeypatch):
|
||||||
config = {"spc": {"api_url": "http://localhost/", "ws_url": "ws://localhost/"}}
|
config = {"spc": {"api_url": "http://localhost/", "ws_url": "ws://localhost/"}}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pyspcwebgw.SpcWebGateway.async_load_parameters", return_value=mock_coro(True)
|
"homeassistant.components.spc.SpcWebGateway.async_load_parameters",
|
||||||
|
return_value=mock_coro(True),
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, "spc", config) is True
|
assert await async_setup_component(hass, "spc", config) is True
|
||||||
|
|
||||||
|
@ -23,7 +24,8 @@ async def test_invalid_device_config(hass, monkeypatch):
|
||||||
config = {"spc": {"api_url": "http://localhost/"}}
|
config = {"spc": {"api_url": "http://localhost/"}}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pyspcwebgw.SpcWebGateway.async_load_parameters", return_value=mock_coro(True)
|
"homeassistant.components.spc.SpcWebGateway.async_load_parameters",
|
||||||
|
return_value=mock_coro(True),
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, "spc", config) is False
|
assert await async_setup_component(hass, "spc", config) is False
|
||||||
|
|
||||||
|
@ -45,11 +47,11 @@ async def test_update_alarm_device(hass):
|
||||||
area_mock.verified_alarm = False
|
area_mock.verified_alarm = False
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pyspcwebgw.SpcWebGateway.areas", new_callable=PropertyMock
|
"homeassistant.components.spc.SpcWebGateway.areas", new_callable=PropertyMock
|
||||||
) as mock_areas:
|
) as mock_areas:
|
||||||
mock_areas.return_value = {"1": area_mock}
|
mock_areas.return_value = {"1": area_mock}
|
||||||
with patch(
|
with patch(
|
||||||
"pyspcwebgw.SpcWebGateway.async_load_parameters",
|
"homeassistant.components.spc.SpcWebGateway.async_load_parameters",
|
||||||
return_value=mock_coro(True),
|
return_value=mock_coro(True),
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, "spc", config) is True
|
assert await async_setup_component(hass, "spc", config) is True
|
||||||
|
|
Loading…
Reference in New Issue