Example #1
0
def get_gateway(**kwargs):
    """Return a gateway instance."""
    _gateway = Gateway(**kwargs)
    _gateway.tasks = SyncTasks(
        _gateway.const, False, None, _gateway.sensors, mock.MagicMock()
    )
    return _gateway
Example #2
0
def gateway(connection_transport, reconnect_callback):
    """Return gateway instance."""
    _gateway = Gateway()
    protocol = BaseMySensorsProtocol(_gateway, reconnect_callback)

    def connect():
        """Connect to device."""
        protocol.connection_made(connection_transport)

    transport = Transport(gateway, connect)
    transport.connect = connect
    transport.protocol = protocol
    _gateway.tasks = SyncTasks(_gateway.const, False, None, _gateway.sensors,
                               transport)
    return _gateway
Example #3
0
 def test_callback_exception(self):
     """Test gateway callback with exception."""
     side_effect = ValueError('test')
     self.gateway = Gateway(event_callback=self._callback)
     with mock.patch.object(self.gateway, 'event_callback',
                            side_effect=side_effect) as mock_callback:
         with self.assertLogs(level='ERROR') as test_handle:
             msg = Message()
             msg.node_id = 1
             self.gateway.alert(msg)
         assert mock_callback.called
         self.assertEqual(
             # only check first line of error log
             test_handle.output[0].split('\n', 1)[0],
             'ERROR:mysensors:test')
Example #4
0
def test_gateway_low_protocol():
    """Test initializing gateway with too low protocol_version."""
    gateway = Gateway(protocol_version='1.3')
    assert gateway.protocol_version == '1.4'
Example #5
0
def test_gateway_bad_protocol():
    """Test initializing gateway with a bad protocol_version."""
    gateway = Gateway(protocol_version=None)
    assert gateway.protocol_version == '1.4'
Example #6
0
 def setUp(self):
     """Set up gateway."""
     self.gateway = Gateway(protocol_version='2.0')
Example #7
0
 def test_persistence_at_init(self, mock_load_sensors):
     """Test call to load persistence_file at init of Gateway."""
     self.gateway = Gateway(persistence=True)
     assert mock_load_sensors.called
Example #8
0
 def setUp(self):
     """Set up gateway."""
     self.gateway = Gateway()
Example #9
0
def get_gateway(**kwargs):
    """Return a gateway instance."""
    return Gateway(**kwargs)
Example #10
0
def gateway(request):
    """Return gateway instance."""
    return Gateway(protocol_version=request.param)
Example #11
0
def gateway():
    """Return gateway instance."""
    return Gateway()
Example #12
0
def get_gateway(protocol_version):
    """Return a gateway."""
    gateway = Gateway(protocol_version=protocol_version)
    return gateway
Example #13
0
def get_gateway(**kwargs):
    """Return a gateway instance."""
    _gateway = Gateway(**kwargs)
    _gateway.tasks = SyncTasks(_gateway.const, True, "mysensors.pickle",
                               _gateway.sensors, mock.MagicMock())
    return _gateway
Example #14
0
def get_gateway(**kwargs):
    """Return a gateway."""
    return Gateway(**kwargs)