Add automation mqtt tests

This commit is contained in:
Paulus Schoutsen 2015-08-10 23:11:46 -07:00
parent eecc51c92d
commit 291cc62381
7 changed files with 228 additions and 34 deletions

View file

@ -6,6 +6,7 @@ Helper method for writing tests.
"""
import os
from datetime import timedelta
from unittest import mock
import homeassistant as ha
import homeassistant.util.dt as dt_util
@ -13,7 +14,7 @@ from homeassistant.helpers.entity import ToggleEntity
from homeassistant.const import (
STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME, EVENT_TIME_CHANGED,
EVENT_STATE_CHANGED)
from homeassistant.components import sun
from homeassistant.components import sun, mqtt
def get_test_config_dir():
@ -52,6 +53,14 @@ def mock_service(hass, domain, service):
return calls
def fire_mqtt_message(hass, topic, payload, qos=0):
hass.bus.fire(mqtt.EVENT_MQTT_MESSAGE_RECEIVED, {
mqtt.ATTR_TOPIC: topic,
mqtt.ATTR_PAYLOAD: payload,
mqtt.ATTR_QOS: qos,
})
def fire_time_changed(hass, time):
hass.bus.fire(EVENT_TIME_CHANGED, {'now': time})
@ -93,6 +102,16 @@ def mock_http_component(hass):
hass.config.components.append('http')
def mock_mqtt_component(hass):
with mock.patch('homeassistant.components.mqtt.MQTT'):
mqtt.setup(hass, {
mqtt.DOMAIN: {
mqtt.CONF_BROKER: 'mock-broker',
}
})
hass.config.components.append(mqtt.DOMAIN)
class MockHTTP(object):
""" Mocks the HTTP module. """