Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #10773: Demo Alarm Broken #10777

Merged
merged 5 commits into from
Nov 25, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion homeassistant/components/alarm_control_panel/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import homeassistant.components.alarm_control_panel.manual as manual
from homeassistant.const import (
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_NIGHT,
STATE_ALARM_TRIGGERED, CONF_PENDING_TIME)
STATE_ALARM_ARMED_CUSTOM_BYPASS, STATE_ALARM_TRIGGERED, CONF_PENDING_TIME)


def setup_platform(hass, config, add_devices, discovery_info=None):
Expand All @@ -23,6 +23,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
STATE_ALARM_ARMED_NIGHT: {
CONF_PENDING_TIME: 5
},
STATE_ALARM_ARMED_CUSTOM_BYPASS: {
CONF_PENDING_TIME: 5
},
STATE_ALARM_TRIGGERED: {
CONF_PENDING_TIME: 5
},
Expand Down
13 changes: 12 additions & 1 deletion tests/components/alarm_control_panel/test_manual.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""The tests for the manual Alarm Control Panel component."""
from datetime import timedelta
import unittest
from unittest.mock import patch
from unittest.mock import patch, MagicMock
from homeassistant.components.alarm_control_panel import demo


from homeassistant.setup import setup_component
from homeassistant.const import (
Expand All @@ -11,6 +13,8 @@
from homeassistant.components import alarm_control_panel
import homeassistant.util.dt as dt_util

from tests.common import assert_setup_component

Choose a reason for hiding this comment

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

'tests.common.assert_setup_component' imported but unused


from tests.common import fire_time_changed, get_test_home_assistant

CODE = 'HELLO_CODE'
Expand All @@ -27,6 +31,13 @@ def tearDown(self): # pylint: disable=invalid-name
"""Stop down everything that was started."""
self.hass.stop()

def test_setup_demo_platform(self):
"""Test setup."""
mock = MagicMock();

Choose a reason for hiding this comment

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

statement ends with a semicolon

add_devices = mock.MagicMock()
Copy link
Member

Choose a reason for hiding this comment

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

What's this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's the code you originally suggested. I had to import MagicMock as it wasn't already imported in this file and and to define what mock was.

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be like this, since you import MagicMock:

add_devices = MagicMock()

demo.setup_platform(self.hass, {}, add_devices)
add_devices.assert_called_once()

def test_arm_home_no_pending(self):
"""Test arm home method."""
self.assertTrue(setup_component(
Expand Down