Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def async_turn_on(self, **kwargs) -> None:
"""Turn the entity on"""
try:
device = self._thermostat.device()
if device.auth():
device.set_power(BROADLINK_POWER_ON)
device.set_mode(BROADLINK_MODE_MANUAL, 0, self.thermostat_get_sensor())
device.set_temp(self._max_temp if self._turn_on_mode == BROADLINK_MAX_TEMP else self._turn_on_mode)
except timeout:
pass
self._state = STATE_ON
await self.async_update_ha_state()
def turn_on(self):
"""Turn the media player on.
Use a different command for Android as WOL is not working.
"""
if self._android:
self._braviarc.turn_on_command()
else:
self._braviarc.turn_on()
# Show that TV is starting while it takes time
# before program info is available
self._reset_playing_info()
self._state = STATE_ON
self._program_name = TV_WAIT
async def async_update(self):
"""Update the state from the template."""
try:
state = self._template.async_render().lower()
if state in _VALID_STATES:
self._state = state in ("true", STATE_ON)
else:
_LOGGER.error(
"Received invalid switch is_on state: %s. Expected: %s",
state,
", ".join(_VALID_STATES),
)
self._state = None
except TemplateError as ex:
_LOGGER.error(ex)
self._state = None
for property_name, template in (
("_icon", self._icon_template),
("_entity_picture", self._entity_picture_template),
("_available", self._availability_template),
def is_on(self):
"""Return true if device is on."""
return self._state == STATE_ON
OP_FAN_MODE : { 0 : STATE_AUTO, 1 : STATE_LOW, 2 : STATE_MEDIUM, 3 : STATE_HIGH, 4 : STATE_TURBO },
OP_FAN_MODE_MAX : { 0 : STATE_AUTO, 1 : STATE_LOW, 2 : STATE_MEDIUM, 3 : STATE_HIGH, 4 : STATE_TURBO },
OP_SWING : { RAC_STATE_ALL : STATE_ALL, RAC_STATE_UP_DOWN : STATE_UP_DOWN, RAC_STATE_LEFT_RIGHT : STATE_LEFT_RIGHT, RAC_STATE_FIX : STATE_FIX },
OP_POWER : { RAC_STATE_OFF : STATE_OFF, RAC_STATE_ON : STATE_ON },
OP_BEEP : { RAC_STATE_BEEP_ON : STATE_ON, RAC_STATE_BEEP_OFF : STATE_OFF },
}
HA_STATE_TO_DEVICE = {
OP_SPECIAL_MODE : { STATE_OFF : RAC_STATE_SPECIAL_MODE_OFF, STATE_SLEEP : RAC_STATE_SLEEP, STATE_SPEED : RAC_STATE_SPEED, STATE_2STEP : RAC_STATE_2STEP, STATE_COMFORT : RAC_STATE_COMFORT, STATE_QUIET : RAC_STATE_QUIET, STATE_SMART : RAC_STATE_SMART },
OP_PURIFY : { STATE_OFF : RAC_STATE_PURIFY_OFF, STATE_ON : RAC_STATE_PURIFY_ON, False : RAC_STATE_OFF, True : RAC_STATE_ON },
OP_CLEAN : { STATE_OFF : RAC_STATE_CLEAN_OFF, STATE_ON : RAC_STATE_CLEAN_ON, False : RAC_STATE_OFF, True : RAC_STATE_ON },
OP_MODE : { STATE_OFF : RAC_STATE_OFF, STATE_HEAT : RAC_STATE_HEAT, STATE_COOL : RAC_STATE_COOL, STATE_DRY : RAC_STATE_DRY, STATE_FAN_ONLY : RAC_STATE_WIND, STATE_AUTO : RAC_STATE_AUTO },
OP_FAN_MODE : { STATE_AUTO : 0, STATE_LOW : 1, STATE_MEDIUM : 2, STATE_HIGH : 3, STATE_TURBO : 4 },
OP_FAN_MODE_MAX : { STATE_AUTO : 0, STATE_LOW : 1, STATE_MEDIUM : 2, STATE_HIGH : 3, STATE_TURBO : 4 },
OP_SWING : { STATE_ALL : RAC_STATE_ALL, STATE_UP_DOWN : RAC_STATE_UP_DOWN, STATE_LEFT_RIGHT : RAC_STATE_LEFT_RIGHT, STATE_FIX : RAC_STATE_FIX },
OP_POWER : { STATE_OFF : RAC_STATE_OFF, STATE_ON : RAC_STATE_ON, False : RAC_STATE_OFF, True : RAC_STATE_ON },
OP_BEEP : { STATE_OFF : RAC_STATE_BEEP_OFF, STATE_ON : RAC_STATE_BEEP_ON, False : RAC_STATE_OFF, True : RAC_STATE_ON },
}
AVAILABLE_COMMANDS_MAP = {
OP_SPECIAL_MODE : ['/devices/0/mode', '{left_bracket}"options": ["{value}"]{right_bracket}'],
OP_PURIFY : ['/devices/0/mode', '{left_bracket}"options": ["{value}"]{right_bracket}'],
OP_CLEAN : ['/devices/0/mode', '{left_bracket}"options": ["{value}"]{right_bracket}'],
OP_GOOD_SLEEP : ['/devices/0/mode', '{left_bracket}"options": ["Sleep_{value}"]{right_bracket}'],
OP_BEEP : ['/devices/0/mode', '{left_bracket}"options": ["{value}"]{right_bracket}'],
OP_MODE : ['/devices/0/mode', '{left_bracket}"modes": ["{value}"]{right_bracket}'],
OP_TARGET_TEMP : ['/devices/0/temperatures/0', '{left_bracket}"desired": {value}{right_bracket}'],
OP_TEMP_MIN : ['/devices/0/temperatures/0', '{left_bracket}"minimum": {value}{right_bracket}'],
OP_TEMP_MAX : ['/devices/0/temperatures/0', '{left_bracket}"maximum": {value}{right_bracket}'],
OP_FAN_MODE : ['/devices/0/wind', '{left_bracket}"speedLevel": {value}{right_bracket}'],
OP_FAN_MODE_MAX : ['/devices/0/wind', '{left_bracket}"maxSpeedLevel": {value}{right_bracket}'],
OP_SWING : ['/devices/0/wind', '{left_bracket}"direction": "{value}"{right_bracket}'],
def async_restore_last_state(self, last_state):
"""Restore previous state."""
super().async_restore_last_state(last_state)
self._state = last_state.state == STATE_ON
def state(self):
"""Return the state of the device."""
if self._state.get_power():
return STATE_ON
return STATE_OFF
def async_condition_from_config(
config: ConfigType, config_validation: bool
) -> condition.ConditionCheckerType:
"""Create a function to test a device condition."""
if config_validation:
config = CONDITION_SCHEMA(config)
if config[CONF_TYPE] == "is_playing":
state = STATE_PLAYING
elif config[CONF_TYPE] == "is_idle":
state = STATE_IDLE
elif config[CONF_TYPE] == "is_paused":
state = STATE_PAUSED
elif config[CONF_TYPE] == "is_on":
state = STATE_ON
else:
state = STATE_OFF
def test_is_state(hass: HomeAssistant, variables: TemplateVarsType) -> bool:
"""Test if an entity is a certain state."""
return condition.state(hass, config[ATTR_ENTITY_ID], state)
return test_is_state
_LOGGER.debug('incorporating timer for ' + timer + ' minutes')
packet = crc_sign_full_packet_com_key(SEND_CONTROL_PACKET.format(session_id, ts, device_id, phone_id, device_password, cmd, convert_minutes_to_timer(timer)))
if not packet is None:
sock.send(ba.unhexlify(packet))
res = sock.recv(1024)
if cmd == "0":
_LOGGER.debug('control packet sent for state off')
status = STATE_OFF
elif cmd == "1":
_LOGGER.debug('control packet sent for state on')
power_w = power_a = 0
if not timer is None:
auto_off_time_left = convert_seconds_to_iso_time(str(int(timer) * 60))
status = STATE_ON
except:
_LOGGER.error('failed to send control packet ' + traceback.format_exc())
return status, power_w, power_a, auto_off_time_left
async def async_set_operation_mode(self, operation_mode: str) -> None:
"""Set new operation mode for a DHW controller.
Except for Auto, the mode is only until the next SetPoint.
"""
if operation_mode == STATE_AUTO:
await self._call_client_api(self._evo_device.set_dhw_auto())
else:
await self._update_schedule()
until = parse_datetime(str(self.setpoints.get("next_sp_from")))
if operation_mode == STATE_ON:
await self._call_client_api(self._evo_device.set_dhw_on(until))
else: # STATE_OFF
await self._call_client_api(self._evo_device.set_dhw_off(until))