Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_setup_us_failures(self, mock_sc):
"""Test the US setup."""
hass = mock.MagicMock()
add_entities = mock.MagicMock()
config = {
CONF_USERNAME: "user",
CONF_PASSWORD: "pass",
honeywell.CONF_REGION: "us",
}
mock_sc.side_effect = somecomfort.AuthError
result = honeywell.setup_platform(hass, config, add_entities)
assert not result
assert not add_entities.called
mock_sc.side_effect = somecomfort.SomeComfortError
result = honeywell.setup_platform(hass, config, add_entities)
assert not result
assert not add_entities.called
def test_set_temp_fail(self):
"""Test if setting the temperature fails."""
self.device.setpoint_heat = mock.MagicMock(
side_effect=somecomfort.SomeComfortError
)
self.honeywell.set_temperature(temperature=123)
def test_setup_us_failures(self, mock_sc):
"""Test the US setup."""
hass = mock.MagicMock()
add_devices = mock.MagicMock()
config = {
CONF_USERNAME: 'user',
CONF_PASSWORD: 'pass',
'region': 'us',
}
mock_sc.side_effect = somecomfort.AuthError
result = honeywell.setup_platform(hass, config, add_devices)
self.assertFalse(result)
self.assertFalse(add_devices.called)
mock_sc.side_effect = somecomfort.SomeComfortError
result = honeywell.setup_platform(hass, config, add_devices)
self.assertFalse(result)
self.assertFalse(add_devices.called)
def test_set_temp_fail(self):
"""Test if setting the temperature fails."""
self.device.setpoint_heat = mock.MagicMock(
side_effect=somecomfort.SomeComfortError)
self.honeywell.set_temperature(123)
if not device:
print('Device not found')
return 1
if any([args.hold_until, args.cancel_hold, args.permanent_hold,
args.get_hold]):
cont = do_holds(client, args, device)
if not cont:
return
try:
return get_or_set_things(
client, args, device,
number_things + string_things,
number_things + string_things + readonly_things)
except somecomfort.SomeComfortError as ex:
print('%s: %s' % (ex.__class__.__name__, str(ex)))
def _turn_away_mode_on(self) -> None:
"""Turn away on.
Somecomfort does have a proprietary away mode, but it doesn't really
work the way it should. For example: If you set a temperature manually
it doesn't get overwritten when away mode is switched on.
"""
self._away = True
try:
# Get current mode
mode = self._device.system_mode
except somecomfort.SomeComfortError:
_LOGGER.error("Can not get system mode")
return
try:
# Set permanent hold
setattr(self._device, f"hold_{mode}", True)
# Set temperature
setattr(
self._device, f"setpoint_{mode}", getattr(self, f"_{mode}_away_temp")
)
except somecomfort.SomeComfortError:
_LOGGER.error(
"Temperature %.1f out of range", getattr(self, f"_{mode}_away_temp")
)
if not device:
print('Device not found')
return 1
if any([args.hold_until, args.cancel_hold, args.permanent_hold,
args.get_hold]):
cont = do_holds(client, args, device)
if not cont:
return
try:
return get_or_set_things(
client, args, device,
number_things + string_things,
number_things + string_things + readonly_things)
except somecomfort.SomeComfortError as ex:
print('%s: %s' % (ex.__class__.__name__, str(ex)))
def set_temperature(self, temperature):
"""Set target temperature."""
import somecomfort
try:
if self._device.system_mode == 'cool':
self._device.setpoint_cool = temperature
else:
self._device.setpoint_heat = temperature
except somecomfort.SomeComfortError:
_LOGGER.error('Temperature %.1f out of range', temperature)