anonym-tsk / home-assistant-components Goto Github PK
View Code? Open in Web Editor NEWCustom components for Home Assistant
Custom components for Home Assistant
First of all, thank you very much for your work.
Yesterday, I put in the addon.
My air conditioner (Midea) can set the temperature in automatic mode.
Is there a possibility to display the option for adjustment here?
Thanks
Wanted to share my work, ir switch with template or ping. I use it mainly for TV.
import asyncio
from functools import partial
import logging
import time
import datetime
import voluptuous as vol
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
from homeassistant.components.binary_sensor.ping import (PingData)
from homeassistant.components.remote import (
ATTR_COMMAND, DOMAIN, SERVICE_SEND_COMMAND)
from homeassistant.const import (
ATTR_ENTITY_ID, CONF_HOST, CONF_NAME, CONF_TOKEN, STATE_OFF, STATE_ON)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.util import Throttle
from homeassistant.helpers.event import async_track_state_change
from homeassistant.core import callback
from homeassistant.exceptions import TemplateError
DEPENDENCIES = ['remote']
_LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = 'IR Switch'
CONF_REMOTE = 'remote'
CONF_PING = 'ping'
CONF_POWER_TEMPLATE = 'power_template'
CONF_COMMANDS = 'commands'
COMMAND_TURN_OFF = 'turn_off'
COMMAND_TURN_ON = 'turn_on'
COMMANDS_SCHEMA = vol.Schema({
vol.Required(COMMAND_TURN_OFF): cv.string,
vol.Required(COMMAND_TURN_ON): cv.string,
}, extra=vol.ALLOW_EXTRA)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Required(CONF_REMOTE): cv.entity_id,
vol.Optional(CONF_PING): cv.string,
vol.Optional(CONF_POWER_TEMPLATE): cv.template,
vol.Required(CONF_COMMANDS): COMMANDS_SCHEMA
})
MIN_TIME_BETWEEN_UPDATES = datetime.timedelta(seconds=10)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the xiaomi remote climate platform."""
name = config.get(CONF_NAME)
remote_entity_id = config.get(CONF_REMOTE)
ping = config.get(CONF_PING)
power_template = config.get(CONF_POWER_TEMPLATE)
commands = config.get(CONF_COMMANDS)
if ping:
async_add_entities([
RemoteSwitch(hass, name, remote_entity_id, commands, power_template, PingData(ping, 1))
])
else:
async_add_entities([
RemoteSwitch(hass, name, remote_entity_id, commands, power_template, ping)
])
class RemoteSwitch(SwitchDevice, RestoreEntity):
def __init__(self, hass, name, remote_entity_id, commands, power_template, ping):
self.hass = hass
self._name = name
self._remote_entity_id = remote_entity_id
self._commands = commands
self._state = None
self._skip_update = False
self._power_template = power_template
if power_template:
self._power_template.hass = hass
self._ping = ping
# if power_template:
# power_template.hass = hass
# power_entity_ids = power_template.extract_entities()
# async_track_state_change(hass, power_entity_ids, self._async_power_changed)
@property
def name(self):
"""Return the name of the climate device."""
return self._name
@property
def is_on(self):
if self._ping:
return self._ping.available
else:
return self._state
@property
def available(self) -> bool:
return True
def _send_command(self, command_name):
if command_name in self._commands:
command = self._commands[command_name]
if command is not None:
self.hass.services.call(DOMAIN, SERVICE_SEND_COMMAND, {
ATTR_COMMAND: 'raw:' + command,
ATTR_ENTITY_ID: self._remote_entity_id
})
def turn_on(self):
if not self.is_on:
self._send_command('turn_on')
self._state = True
if self._ping:
self._ping.available = True
self._skip_update = True
self.schedule_update_ha_state()
def turn_off(self):
if self.is_on:
self._send_command('turn_off')
self._state = False
if self._ping:
self._ping.available = False
self._skip_update = True
self.schedule_update_ha_state()
@callback
def _async_update_power(self):
try:
if self._power_template.async_render().lower() not in ('true', 'on', '1'):
self._state = False
else:
self._state = True
except TemplateError as ex:
_LOGGER.warning('Unable to update power from template: %s', ex)
@Throttle(MIN_TIME_BETWEEN_UPDATES)
async def async_update(self):
if self._skip_update:
self._skip_update = False
return
if self._ping:
self._ping.update()
elif self._power_template:
self._async_update_power()
Here you can find ir codes example:
https://www.dropbox.com/s/texllwcvx3sxnqe/ir_remote_codes.rar?dl=0&file_subpath=%2Fir_remote_codes%2Fswitch
Why not asking to integrate this component into the official hass release?
Please help to check, I have this error after update to HA 0.80
AttributeError: module 'homeassistant.components.remote' has no attribute 'send_command'
When I restart home assistant. If ac is turned off, it will become on after reboot.
Hi,
when I create the commands.yaml file I get this error
expected dict for dictionary value @ data['comandi']['off'] Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/homeassistant/components/websocket_api/commands.py", line 122, in handle_call_service connection.context(msg)) File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1138, in async_call self._execute_service(handler, service_call)) File "/usr/local/lib/python3.7/site-packages/homeassistant/core.py", line 1160, in _execute_service await handler.func(service_call) File "/usr/local/lib/python3.7/site-packages/homeassistant/components/automation/__init__.py", line 155, in reload_service_handler conf = await component.async_prepare_reload() File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/entity_component.py", line 272, in async_prepare_reload conf_util.async_hass_config_yaml(self.hass) File "/usr/local/lib/python3.7/site-packages/homeassistant/config.py", line 318, in async_hass_config_yaml return await hass.async_add_executor_job(_load_hass_yaml_config) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.7/site-packages/homeassistant/config.py", line 315, in _load_hass_yaml_config merge_packages_config(hass, config, core_config.get(CONF_PACKAGES, {})) File "/usr/local/lib/python3.7/site-packages/homeassistant/config.py", line 644, in merge_packages_config PACKAGES_CONFIG_SCHEMA(packages) File "/usr/local/lib/python3.7/site-packages/homeassistant/helpers/config_validation.py", line 391, in verify return schema(value) File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 267, in __call__ return self._compiled([], data) File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 589, in validate_dict return base_validate(path, iteritems(data), out) File "/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py", line 427, in validate_mapping raise er.MultipleInvalid(errors) voluptuous.error.MultipleInvalid: **expected dict for dictionary value @ data['comandi']['off']**
I simply copypasted the one you provided
I have understood that from 0.89 of HA the custom components needs to be structured different or has to contain moe files? At least from my exprience the custom component Xiaomi IR Climate wihich i am very happy that you have built, stopped working. Is there a need to do changes to the component, or is it just me who does not understand what to do?
Hello.
I just setup Heaty and get thoses errors:
2018-09-24 14:54:34.336509 INFO AppDaemon: Initializing app heaty_full using class HeatyApp from module hass_apps_loader
2018-09-24 14:54:34.470211 INFO heaty_full: *** Welcome to heaty (version 0.16.0)!
2018-09-24 14:54:34.471668 INFO heaty_full: ***
2018-09-24 14:54:34.472458 INFO heaty_full: *** This is an app from the hass-apps package.
2018-09-24 14:54:34.473171 INFO heaty_full: *** DOCS: https://hass-apps.readthedocs.io/en/stable/
2018-09-24 14:54:34.474168 INFO heaty_full: ***
2018-09-24 14:54:34.475276 INFO heaty_full: *** If you like this app and want to honor the effort put into it,
2018-09-24 14:54:34.476486 INFO heaty_full: *** please consider a donation.
2018-09-24 14:54:34.477710 INFO heaty_full: *** DONATE: https://hass-apps.readthedocs.io/en/stable/#donations
2018-09-24 14:54:34.478870 INFO heaty_full: *** Thank you very much and enjoy heaty!
2018-09-24 14:54:34.479704 INFO heaty_full: ***
2018-09-24 14:54:34.480358 INFO heaty_full: --- Validating the app's configuration.
2018-09-24 14:54:34.484016 INFO heaty_full: --- Heaty id is: 'default'
2018-09-24 14:54:34.484795 INFO heaty_full: --- Importing modules for use in temperature expressions.
2018-09-24 14:54:34.485888 INFO heaty_full: --- [R:Room Rose] Initializing room (name='rose').
2018-09-24 14:54:34.487364 INFO heaty_full: <-- [R:Room Rose] Querying state of 'sensor.heaty_default_room_rose_scheduled_temp'.
2018-09-24 14:54:34.488920 INFO heaty_full: --> [R:Room Rose] = None
2018-09-24 14:54:34.490124 INFO heaty_full: --- [R:Room Rose] Last scheduled temperature is unknown.
2018-09-24 14:54:34.491298 INFO heaty_full: --- [R:Room Rose] [T:climate.air_conditioner_rose] Initializing thermostat (entity_id='climate.air_conditioner_ros
e').
2018-09-24 14:54:34.492428 WARNING heaty_full: !!! [R:Room Rose] [T:climate.air_conditioner_rose] Thermostat has no attribute named 'operation_mode'. Availabl
e attributes are ['current_temperature', 'friendly_name', 'max_temp', 'min_temp', 'power', 'supported_features', 'target_temp_step', 'temperature', 'attribute
s', 'context', 'entity_id', 'last_changed', 'last_updated', 'state']. Please check your config!
2018-09-24 14:54:34.494601 WARNING heaty_full: !!! [R:Room Rose] [T:climate.air_conditioner_rose] The value None for attribute 'current_temperature' is no val
id temperature value. Please check your config!
2018-09-24 14:54:34.495640 WARNING heaty_full: !!! [R:Room Rose] [T:climate.air_conditioner_rose] Attributes for thermostat contain no 'operation_list', Consi
der disabling operation mode support.
2018-09-24 14:54:34.496717 INFO heaty_full: --- [R:Room Rose] [T:climate.air_conditioner_rose] Fetching initial state.
2018-09-24 14:54:34.497864 INFO heaty_full: --> [R:Room Rose] [T:climate.air_conditioner_rose] Attribute 'operation_mode' is None.
2018-09-24 14:54:34.499195 ERROR heaty_full: !!! [R:Room Rose] [T:climate.air_conditioner_rose] Unknown operation mode, ignoring thermostat.
2018-09-24 14:54:34.500749 INFO heaty_full: --- [R:Room Rose] [T:climate.air_conditioner_rose] Listening for state changes.
2018-09-24 14:54:34.502123 INFO heaty_full: --- [R:Room Rose] [W:binary_sensor.door_window_sensor_158d00019daf13] Initializing window sensor (entity_id='binar
y_sensor.door_window_sensor_158d00019daf13').
2018-09-24 14:54:34.503046 INFO heaty_full: --- [R:Room Rose] [W:binary_sensor.door_window_sensor_158d00019daf13] Listening for state changes (delay=10).
2018-09-24 14:54:34.503939 INFO heaty_full: --- [R:Room Rose] Registering scheduling timers at: {17:30:00, 07:45:00, 07:15:00, 08:00:00}
2018-09-24 14:54:34.505366 INFO heaty_full: --- [R:Room Evan] Initializing room (name='evan').
2018-09-24 14:54:34.506216 INFO heaty_full: <-- [R:Room Evan] Querying state of 'sensor.heaty_default_room_evan_scheduled_temp'.
2018-09-24 14:54:34.507059 INFO heaty_full: --> [R:Room Evan] = None
2018-09-24 14:54:34.507828 INFO heaty_full: --- [R:Room Evan] Last scheduled temperature is unknown.
2018-09-24 14:54:34.508672 INFO heaty_full: --- [R:Room Evan] [T:climate.air_conditioner_evan] Initializing thermostat (entity_id='climate.air_conditioner_eva
n').
2018-09-24 14:54:34.509777 WARNING heaty_full: !!! [R:Room Evan] [T:climate.air_conditioner_evan] Thermostat has no attribute named 'operation_mode'. Availabl
e attributes are ['current_temperature', 'friendly_name', 'max_temp', 'min_temp', 'power', 'supported_features', 'target_temp_step', 'temperature', 'attribute
s', 'context', 'entity_id', 'last_changed', 'last_updated', 'state']. Please check your config!
2018-09-24 14:54:34.511326 WARNING heaty_full: !!! [R:Room Evan] [T:climate.air_conditioner_evan] The value None for attribute 'current_temperature' is no val
id temperature value. Please check your config!
2018-09-24 14:54:34.513056 WARNING heaty_full: !!! [R:Room Evan] [T:climate.air_conditioner_evan] Attributes for thermostat contain no 'operation_list', Consi
der disabling operation mode support.
2018-09-24 14:54:34.514174 INFO heaty_full: --- [R:Room Evan] [T:climate.air_conditioner_evan] Fetching initial state.
2018-09-24 14:54:34.516112 INFO heaty_full: --> [R:Room Evan] [T:climate.air_conditioner_evan] Attribute 'operation_mode' is None.
2018-09-24 14:54:34.517775 ERROR heaty_full: !!! [R:Room Evan] [T:climate.air_conditioner_evan] Unknown operation mode, ignoring thermostat.
2018-09-24 14:54:34.518937 INFO heaty_full: --- [R:Room Evan] [T:climate.air_conditioner_evan] Listening for state changes.
2018-09-24 14:54:34.519859 INFO heaty_full: --- [R:Room Evan] [W:binary_sensor.door_window_sensor_158d00019dae38] Initializing window sensor (entity_id='binar
y_sensor.door_window_sensor_158d00019dae38').
2018-09-24 14:54:34.520674 INFO heaty_full: --- [R:Room Evan] [W:binary_sensor.door_window_sensor_158d00019dae38] Listening for state changes (delay=10).
2018-09-24 14:54:34.521565 INFO heaty_full: --- [R:Room Evan] Registering scheduling timers at: {07:45:00, 07:15:00, 21:00:00, 22:00:00}
2018-09-24 14:54:34.522749 INFO heaty_full: --- [R:Bedroom] Initializing room (name='bedroom').
2018-09-24 14:54:34.524178 INFO heaty_full: <-- [R:Bedroom] Querying state of 'sensor.heaty_default_room_bedroom_scheduled_temp'.
2018-09-24 14:54:34.525112 INFO heaty_full: --> [R:Bedroom] = None
2018-09-24 14:54:34.526194 INFO heaty_full: --- [R:Bedroom] Last scheduled temperature is unknown.
2018-09-24 14:54:34.527046 INFO heaty_full: --- [R:Bedroom] [T:climate.air_conditioner_bedroom] Initializing thermostat (entity_id='climate.air_conditioner_be
droom').
2018-09-24 14:54:34.528144 WARNING heaty_full: !!! [R:Bedroom] [T:climate.air_conditioner_bedroom] Thermostat has no attribute named 'operation_mode'. Availab
le attributes are ['current_temperature', 'friendly_name', 'max_temp', 'min_temp', 'power', 'supported_features', 'target_temp_step', 'temperature', 'attribut
es', 'context', 'entity_id', 'last_changed', 'last_updated', 'state']. Please check your config!
2018-09-24 14:54:34.529170 WARNING heaty_full: !!! [R:Bedroom] [T:climate.air_conditioner_bedroom] The value None for attribute 'current_temperature' is no va
lid temperature value. Please check your config!
2018-09-24 14:54:34.530216 WARNING heaty_full: !!! [R:Bedroom] [T:climate.air_conditioner_bedroom] Attributes for thermostat contain no 'operation_list', Cons
ider disabling operation mode support.
2018-09-24 14:54:34.531375 INFO heaty_full: --- [R:Bedroom] [T:climate.air_conditioner_bedroom] Fetching initial state.
2018-09-24 14:54:34.532468 INFO heaty_full: --> [R:Bedroom] [T:climate.air_conditioner_bedroom] Attribute 'operation_mode' is None.
2018-09-24 14:54:34.533414 ERROR heaty_full: !!! [R:Bedroom] [T:climate.air_conditioner_bedroom] Unknown operation mode, ignoring thermostat.
2018-09-24 14:54:34.534642 INFO heaty_full: --- [R:Bedroom] [T:climate.air_conditioner_bedroom] Listening for state changes.
2018-09-24 14:54:34.536127 INFO heaty_full: --- [R:Bedroom] [W:binary_sensor.door_window_sensor_158d00019f308a] Initializing window sensor (entity_id='binary_
sensor.door_window_sensor_158d00019f308a').
2018-09-24 14:54:34.537419 INFO heaty_full: --- [R:Bedroom] [W:binary_sensor.door_window_sensor_158d00019f308a] Listening for state changes (delay=10).
2018-09-24 14:54:34.538453 INFO heaty_full: --- [R:Bedroom] Registering scheduling timers at: {23:30:00, 22:30:00}
2018-09-24 14:54:34.539308 INFO heaty_full: --- Listening for heaty_reschedule event.
2018-09-24 14:54:34.540097 INFO heaty_full: --- Listening for heaty_set_temp event.
2018-09-24 14:54:34.540846 INFO heaty_full: --- Listening for state changes of master switch (entity_id='input_boolean.heating_master').
2018-09-24 14:54:34.540981 WARNING AppDaemon: heaty_full: Entity input_boolean.heating_master not found in AppDaemon
2018-09-24 14:54:34.541779 INFO heaty_full: --- Master switch is off, not setting temperatures initially.
2018-09-24 14:54:34.542768 INFO heaty_full: --- [SZ:upstairs] Initializing statistics zone (name='upstairs').
2018-09-24 14:54:34.543616 WARNING heaty_full: !!! [SZ:upstairs] No parameters configured.
2018-09-24 14:54:34.544418 INFO heaty_full: --- [SZ:upstairs] Listening for temperature changes of T:climate.air_conditioner_rose in R:Room Rose.
2018-09-24 14:54:34.545224 INFO heaty_full: --- [SZ:upstairs] Listening for temperature changes of T:climate.air_conditioner_evan in R:Room Evan.
2018-09-24 14:54:34.546169 INFO heaty_full: --- [SZ:upstairs] Listening for temperature changes of T:climate.air_conditioner_bedroom in R:Bedroom.
2018-09-24 14:54:34.547649 INFO heaty_full: --- [SZ:upstairs] Going to update statistics in 3 seconds.
2018-09-24 14:54:34.549031 INFO heaty_full: *** Initialization done.
2018-09-24 14:54:34.549722 INFO AppDaemon: App initialization complete
2018-09-24 14:54:37.003532 INFO heaty_full: --- [SZ:upstairs] No parameters configured, nothing to update.
Problem is that your component doesn't expose operation mode?
That's weird as I can use this operation_mode in my automations.
Could you please have a look?
THanks .)
Your fan
Hi unfortunately there was a rewrite of the climate component and this custom component doesn't work anymore ..is it possible to adjust it?
Thanks in advance
Suggesting to add Custom Updater support for easy tracking and updates
https://github.com/custom-components/custom_updater
https://github.com/custom-cards/tracker-card
Here is IR Remote Vacuum Component.
It has power_template docking mode and timeout in minutes cleaning/docking mode.
Power_template mode is not fully tested.
It also has special brand mode, irobot is implemented.
"""
Support for the Xiaomi vacuum cleaner robot.
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/vacuum.xiaomi_miio/
"""
import asyncio
from functools import partial
import logging
import time
import datetime
import voluptuous as vol
from homeassistant.components.vacuum import (
ATTR_CLEANED_AREA, DOMAIN, PLATFORM_SCHEMA, SUPPORT_BATTERY,
SUPPORT_CLEAN_SPOT, SUPPORT_FAN_SPEED, SUPPORT_LOCATE, SUPPORT_PAUSE,
SUPPORT_RETURN_HOME, SUPPORT_SEND_COMMAND, SUPPORT_STOP,
SUPPORT_STATE, SUPPORT_START, VACUUM_SERVICE_SCHEMA, StateVacuumDevice,
STATE_CLEANING, STATE_DOCKED, STATE_PAUSED, STATE_IDLE, STATE_RETURNING,
STATE_ERROR)
from homeassistant.components.remote import (
ATTR_COMMAND, DOMAIN, SERVICE_SEND_COMMAND)
from homeassistant.const import (
ATTR_ENTITY_ID, CONF_HOST, CONF_NAME, CONF_TOKEN, STATE_OFF, STATE_ON)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.util import Throttle
from homeassistant.helpers.event import async_track_state_change
from homeassistant.core import callback
from homeassistant.exceptions import TemplateError
DEPENDENCIES = ['remote']
_LOGGER = logging.getLogger(__name__)
DEFAULT_NAME = 'IR Vacuum cleaner'
DEFAULT_BRAND = None
DEFAULT_CLEANING_TIME = 60
DEFAULT_TIME_DOCKING = 1
CONF_REMOTE = 'remote'
CONF_BRAND = 'brand'
CONF_TIME_CLEANING = 'time_cleaning'
CONF_TIME_DOCKING = 'time_docking'
CONF_POWER_TEMPLATE = 'power_template'
CONF_COMMANDS = 'commands'
COMMAND_START = 'start'
COMMANDS_SCHEMA = vol.Schema({
vol.Required(COMMAND_START): cv.string
}, extra=vol.ALLOW_EXTRA)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_BRAND, default=DEFAULT_BRAND): cv.string,
vol.Optional(CONF_TIME_CLEANING, default=DEFAULT_CLEANING_TIME): cv.positive_int,
vol.Optional(CONF_TIME_DOCKING, default=DEFAULT_TIME_DOCKING): cv.positive_int,
vol.Required(CONF_REMOTE): cv.entity_id,
vol.Optional(CONF_POWER_TEMPLATE): cv.template,
vol.Required(CONF_COMMANDS): COMMANDS_SCHEMA
})
ATTR_CLEAN_START = 'clean_start'
ATTR_CLEAN_STOP = 'clean_stop'
ATTR_CLEANING_TIME = 'time_cleaning'
ATTR_DO_NOT_DISTURB = 'do_not_disturb'
ATTR_DO_NOT_DISTURB_START = 'do_not_disturb_start'
ATTR_DO_NOT_DISTURB_END = 'do_not_disturb_end'
ATTR_MAIN_BRUSH_LEFT = 'main_brush_left'
ATTR_SIDE_BRUSH_LEFT = 'side_brush_left'
ATTR_FILTER_LEFT = 'filter_left'
ATTR_SENSOR_DIRTY_LEFT = 'sensor_dirty_left'
ATTR_CLEANING_COUNT = 'cleaning_count'
ATTR_CLEANED_TOTAL_AREA = 'total_cleaned_area'
ATTR_CLEANING_TOTAL_TIME = 'total_time_cleaning'
ATTR_ERROR = 'error'
ATTR_RC_DURATION = 'duration'
ATTR_RC_ROTATION = 'rotation'
ATTR_RC_VELOCITY = 'velocity'
ATTR_STATUS = 'status'
MIN_TIME_BETWEEN_UPDATES = datetime.timedelta(seconds=10)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the xiaomi remote climate platform."""
name = config.get(CONF_NAME)
brand = config.get(CONF_BRAND)
time_cleaning = config.get(CONF_TIME_CLEANING)
time_docking = config.get(CONF_TIME_DOCKING)
remote_entity_id = config.get(CONF_REMOTE)
commands = config.get(CONF_COMMANDS)
power_template = config.get(CONF_POWER_TEMPLATE)
async_add_entities([
RemoteVacuum(hass, name, brand, time_cleaning, time_docking, remote_entity_id, commands, power_template)
])
class RemoteVacuum(StateVacuumDevice, RestoreEntity):
def __init__(self, hass, name, brand, time_cleaning, time_docking, remote_entity_id, commands, power_template):
self.hass = hass
self._name = name
self._brand = brand.lower()
self._time_cleaning = time_cleaning * 60
self._time_docking = time_docking * 60
self._remote_entity_id = remote_entity_id
self._commands = commands
s = set()
s.add(SUPPORT_STATE)
if 'start' in commands:
s.add(SUPPORT_START)
if 'stop' in commands:
s.add(SUPPORT_STOP)
if 'pause' in commands:
s.add(SUPPORT_PAUSE)
if 'return_to_base' in commands:
s.add(SUPPORT_RETURN_HOME)
self._support = s
self._state = STATE_DOCKED
self.last_clean = {}
self._skip_update = False
self._power_template = power_template
self.clean_start = time.time()
self.dock_start = time.time()
@property
def name(self):
"""Return the name of the climate device."""
return self._name
@property
def supported_features(self):
"""Flag vacuum cleaner robot features that are supported."""
return self._support
@property
def state(self):
return self._state
@property
def available(self) -> bool:
"""Return True if entity is available."""
return True
@property
def device_state_attributes(self):
"""Return the specific state attributes of this vacuum cleaner."""
attrs = {}
if self._state is not None:
if self.last_clean:
if 'start' in self.last_clean:
attrs[ATTR_CLEAN_START] = self.last_clean['start']
if 'end' in self.last_clean:
attrs[ATTR_CLEAN_STOP] = self.last_clean['end']
return attrs
def _send_command(self, command_name):
if command_name in self._commands:
command = self._commands[command_name]
if command is not None:
self.hass.services.call(DOMAIN, SERVICE_SEND_COMMAND, {
ATTR_COMMAND: 'raw:' + command,
ATTR_ENTITY_ID: self._remote_entity_id
})
if self._brand == 'irobot':
self.hass.services.call(DOMAIN, SERVICE_SEND_COMMAND, {
ATTR_COMMAND: 'raw:' + command,
ATTR_ENTITY_ID: self._remote_entity_id
})
def start(self):
self._send_command('start')
self._state = STATE_CLEANING
if not self._power_template:
self.clean_start = time.time()
else:
self._skip_update = True
self.last_clean['start'] = self.dt()
self.schedule_update_ha_state()
def stop(self):
self._send_command('stop')
self._state = STATE_IDLE
self.last_clean['end'] = self.dt()
self.schedule_update_ha_state()
def pause(self):
self._send_command('pause')
self._state = STATE_PAUSED
self.last_clean['end'] = self.dt()
self.schedule_update_ha_state()
def return_to_base(self):
if self._state == STATE_CLEANING:
self.last_clean['end'] = self.dt()
if self._brand == 'irobot':
self._send_command('start')
time.sleep(2)
self._send_command('return_to_base')
self._state = STATE_RETURNING
if not self._power_template:
self.dock_start = time.time()
self.schedule_update_ha_state()
@callback
def _async_update_power(self):
try:
if self._power_template.async_render().lower() in ('true', 'on', '1'):
self._state = STATE_DOCKED
except TemplateError as ex:
_LOGGER.warning('Unable to update power from template: %s', ex)
def dt(self):
return datetime.datetime.now().strftime("%H:%M:%S %d.%m.%Y")
@Throttle(MIN_TIME_BETWEEN_UPDATES)
async def async_update(self):
if self._skip_update:
self._skip_update = False
return
if not self._power_template:
if self._state == STATE_CLEANING:
time_diff = time.time() - self.clean_start
# _LOGGER.error('STATE_CLEANING %s' % time_diff)
if time_diff > self._time_cleaning:
self.last_clean['end'] = self.dt()
self._state = STATE_DOCKED
self.schedule_update_ha_state()
elif self._state == STATE_RETURNING:
time_diff = time.time() - self.dock_start
# _LOGGER.error('STATE_RETURNING %s' % time_diff)
if time_diff > self._time_docking:
self._state = STATE_DOCKED
self.schedule_update_ha_state()
else:
self.clean_start = None
self.dock_start = None
elif self._power_template:
self._async_update_power()
IR codes example:
https://www.dropbox.com/s/texllwcvx3sxnqe/ir_remote_codes.rar?dl=0&file_subpath=%2Fir_remote_codes%2Fvacuum
I was wondering why the component shows only the set temp and not the actual temp in the graph .
Is it intended or an error?
If not nice nice work mate
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.