Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
sequence
start_point
sequence
end_point
sequence
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
build_frame
( snapshots_num: int, region_amount: int, zone_amount: int, data_center_amount: int, cluster_amount: int, rack_amount: int, pm_amount: int )
Function to build vm_scheduling Frame. Args: snapshot_num (int): Number of in-memory snapshots. region_amount (int): Number of region. zone_amount (int): Number of zone. cluster_amount (int): Number of cluster. pm_amount (int): Number of physical machine. Returns: VmSchedulingFrame: Frame instance for vm_scheduling scenario.
Function to build vm_scheduling Frame.
def build_frame( snapshots_num: int, region_amount: int, zone_amount: int, data_center_amount: int, cluster_amount: int, rack_amount: int, pm_amount: int ): """Function to build vm_scheduling Frame. Args: snapshot_num (int): Number of in-memory snapshots. region_amount (int): Number of region. zone_amount (int): Number of zone. cluster_amount (int): Number of cluster. pm_amount (int): Number of physical machine. Returns: VmSchedulingFrame: Frame instance for vm_scheduling scenario. """ class VmSchedulingFrame(FrameBase): regions = FrameNode(Region, region_amount) zones = FrameNode(Zone, zone_amount) data_centers = FrameNode(DataCenter, data_center_amount) clusters = FrameNode(Cluster, cluster_amount) racks = FrameNode(Rack, rack_amount) pms = FrameNode(PhysicalMachine, pm_amount) def __init__(self): super().__init__(enable_snapshot=True, total_snapshot=snapshots_num) return VmSchedulingFrame()
[ "def", "build_frame", "(", "snapshots_num", ":", "int", ",", "region_amount", ":", "int", ",", "zone_amount", ":", "int", ",", "data_center_amount", ":", "int", ",", "cluster_amount", ":", "int", ",", "rack_amount", ":", "int", ",", "pm_amount", ":", "int", ")", ":", "class", "VmSchedulingFrame", "(", "FrameBase", ")", ":", "regions", "=", "FrameNode", "(", "Region", ",", "region_amount", ")", "zones", "=", "FrameNode", "(", "Zone", ",", "zone_amount", ")", "data_centers", "=", "FrameNode", "(", "DataCenter", ",", "data_center_amount", ")", "clusters", "=", "FrameNode", "(", "Cluster", ",", "cluster_amount", ")", "racks", "=", "FrameNode", "(", "Rack", ",", "rack_amount", ")", "pms", "=", "FrameNode", "(", "PhysicalMachine", ",", "pm_amount", ")", "def", "__init__", "(", "self", ")", ":", "super", "(", ")", ".", "__init__", "(", "enable_snapshot", "=", "True", ",", "total_snapshot", "=", "snapshots_num", ")", "return", "VmSchedulingFrame", "(", ")" ]
[ 13, 0 ]
[ 40, 30 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass)
Enable the Home Assistant views.
Enable the Home Assistant views.
async def async_setup(hass): """Enable the Home Assistant views.""" hass.components.websocket_api.async_register_command( WS_TYPE_LIST, websocket_list, SCHEMA_WS_LIST ) hass.components.websocket_api.async_register_command( WS_TYPE_DELETE, websocket_delete, SCHEMA_WS_DELETE ) hass.components.websocket_api.async_register_command(websocket_create) hass.components.websocket_api.async_register_command(websocket_update) return True
[ "async", "def", "async_setup", "(", "hass", ")", ":", "hass", ".", "components", ".", "websocket_api", ".", "async_register_command", "(", "WS_TYPE_LIST", ",", "websocket_list", ",", "SCHEMA_WS_LIST", ")", "hass", ".", "components", ".", "websocket_api", ".", "async_register_command", "(", "WS_TYPE_DELETE", ",", "websocket_delete", ",", "SCHEMA_WS_DELETE", ")", "hass", ".", "components", ".", "websocket_api", ".", "async_register_command", "(", "websocket_create", ")", "hass", ".", "components", ".", "websocket_api", ".", "async_register_command", "(", "websocket_update", ")", "return", "True" ]
[ 16, 0 ]
[ 26, 15 ]
python
en
['en', 'en', 'en']
True
websocket_list
(hass, connection, msg)
Return a list of users.
Return a list of users.
async def websocket_list(hass, connection, msg): """Return a list of users.""" result = [_user_info(u) for u in await hass.auth.async_get_users()] connection.send_message(websocket_api.result_message(msg["id"], result))
[ "async", "def", "websocket_list", "(", "hass", ",", "connection", ",", "msg", ")", ":", "result", "=", "[", "_user_info", "(", "u", ")", "for", "u", "in", "await", "hass", ".", "auth", ".", "async_get_users", "(", ")", "]", "connection", ".", "send_message", "(", "websocket_api", ".", "result_message", "(", "msg", "[", "\"id\"", "]", ",", "result", ")", ")" ]
[ 31, 0 ]
[ 35, 76 ]
python
en
['en', 'en', 'en']
True
websocket_delete
(hass, connection, msg)
Delete a user.
Delete a user.
async def websocket_delete(hass, connection, msg): """Delete a user.""" if msg["user_id"] == connection.user.id: connection.send_message( websocket_api.error_message( msg["id"], "no_delete_self", "Unable to delete your own account" ) ) return user = await hass.auth.async_get_user(msg["user_id"]) if not user: connection.send_message( websocket_api.error_message(msg["id"], "not_found", "User not found") ) return await hass.auth.async_remove_user(user) connection.send_message(websocket_api.result_message(msg["id"]))
[ "async", "def", "websocket_delete", "(", "hass", ",", "connection", ",", "msg", ")", ":", "if", "msg", "[", "\"user_id\"", "]", "==", "connection", ".", "user", ".", "id", ":", "connection", ".", "send_message", "(", "websocket_api", ".", "error_message", "(", "msg", "[", "\"id\"", "]", ",", "\"no_delete_self\"", ",", "\"Unable to delete your own account\"", ")", ")", "return", "user", "=", "await", "hass", ".", "auth", ".", "async_get_user", "(", "msg", "[", "\"user_id\"", "]", ")", "if", "not", "user", ":", "connection", ".", "send_message", "(", "websocket_api", ".", "error_message", "(", "msg", "[", "\"id\"", "]", ",", "\"not_found\"", ",", "\"User not found\"", ")", ")", "return", "await", "hass", ".", "auth", ".", "async_remove_user", "(", "user", ")", "connection", ".", "send_message", "(", "websocket_api", ".", "result_message", "(", "msg", "[", "\"id\"", "]", ")", ")" ]
[ 40, 0 ]
[ 60, 68 ]
python
en
['es', 'it', 'en']
False
websocket_create
(hass, connection, msg)
Create a user.
Create a user.
async def websocket_create(hass, connection, msg): """Create a user.""" user = await hass.auth.async_create_user(msg["name"], msg.get("group_ids")) connection.send_message( websocket_api.result_message(msg["id"], {"user": _user_info(user)}) )
[ "async", "def", "websocket_create", "(", "hass", ",", "connection", ",", "msg", ")", ":", "user", "=", "await", "hass", ".", "auth", ".", "async_create_user", "(", "msg", "[", "\"name\"", "]", ",", "msg", ".", "get", "(", "\"group_ids\"", ")", ")", "connection", ".", "send_message", "(", "websocket_api", ".", "result_message", "(", "msg", "[", "\"id\"", "]", ",", "{", "\"user\"", ":", "_user_info", "(", "user", ")", "}", ")", ")" ]
[ 72, 0 ]
[ 78, 5 ]
python
co
['es', 'co', 'en']
False
websocket_update
(hass, connection, msg)
Update a user.
Update a user.
async def websocket_update(hass, connection, msg): """Update a user.""" user = await hass.auth.async_get_user(msg.pop("user_id")) if not user: connection.send_message( websocket_api.error_message( msg["id"], websocket_api.const.ERR_NOT_FOUND, "User not found" ) ) return if user.system_generated: connection.send_message( websocket_api.error_message( msg["id"], "cannot_modify_system_generated", "Unable to update system generated users.", ) ) return msg.pop("type") msg_id = msg.pop("id") await hass.auth.async_update_user(user, **msg) connection.send_message( websocket_api.result_message(msg_id, {"user": _user_info(user)}) )
[ "async", "def", "websocket_update", "(", "hass", ",", "connection", ",", "msg", ")", ":", "user", "=", "await", "hass", ".", "auth", ".", "async_get_user", "(", "msg", ".", "pop", "(", "\"user_id\"", ")", ")", "if", "not", "user", ":", "connection", ".", "send_message", "(", "websocket_api", ".", "error_message", "(", "msg", "[", "\"id\"", "]", ",", "websocket_api", ".", "const", ".", "ERR_NOT_FOUND", ",", "\"User not found\"", ")", ")", "return", "if", "user", ".", "system_generated", ":", "connection", ".", "send_message", "(", "websocket_api", ".", "error_message", "(", "msg", "[", "\"id\"", "]", ",", "\"cannot_modify_system_generated\"", ",", "\"Unable to update system generated users.\"", ",", ")", ")", "return", "msg", ".", "pop", "(", "\"type\"", ")", "msg_id", "=", "msg", ".", "pop", "(", "\"id\"", ")", "await", "hass", ".", "auth", ".", "async_update_user", "(", "user", ",", "*", "*", "msg", ")", "connection", ".", "send_message", "(", "websocket_api", ".", "result_message", "(", "msg_id", ",", "{", "\"user\"", ":", "_user_info", "(", "user", ")", "}", ")", ")" ]
[ 91, 0 ]
[ 120, 5 ]
python
co
['es', 'co', 'en']
False
_user_info
(user)
Format a user.
Format a user.
def _user_info(user): """Format a user.""" ha_username = next( ( cred.data.get("username") for cred in user.credentials if cred.auth_provider_type == "homeassistant" ), None, ) return { "id": user.id, "username": ha_username, "name": user.name, "is_owner": user.is_owner, "is_active": user.is_active, "system_generated": user.system_generated, "group_ids": [group.id for group in user.groups], "credentials": [{"type": c.auth_provider_type} for c in user.credentials], }
[ "def", "_user_info", "(", "user", ")", ":", "ha_username", "=", "next", "(", "(", "cred", ".", "data", ".", "get", "(", "\"username\"", ")", "for", "cred", "in", "user", ".", "credentials", "if", "cred", ".", "auth_provider_type", "==", "\"homeassistant\"", ")", ",", "None", ",", ")", "return", "{", "\"id\"", ":", "user", ".", "id", ",", "\"username\"", ":", "ha_username", ",", "\"name\"", ":", "user", ".", "name", ",", "\"is_owner\"", ":", "user", ".", "is_owner", ",", "\"is_active\"", ":", "user", ".", "is_active", ",", "\"system_generated\"", ":", "user", ".", "system_generated", ",", "\"group_ids\"", ":", "[", "group", ".", "id", "for", "group", "in", "user", ".", "groups", "]", ",", "\"credentials\"", ":", "[", "{", "\"type\"", ":", "c", ".", "auth_provider_type", "}", "for", "c", "in", "user", ".", "credentials", "]", ",", "}" ]
[ 123, 0 ]
[ 144, 5 ]
python
en
['es', 'lb', 'en']
False
async_setup_platform
(hass, config, async_add_entities, discovery_info=None)
Set up a Synology IP Camera.
Set up a Synology IP Camera.
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up a Synology IP Camera.""" _LOGGER.warning( "The Synology integration is deprecated." " Please use the Synology DSM integration" " (https://www.home-assistant.io/integrations/synology_dsm/) instead." " This integration will be removed in version 0.118.0." ) verify_ssl = config.get(CONF_VERIFY_SSL) timeout = config.get(CONF_TIMEOUT) try: surveillance = await hass.async_add_executor_job( partial( SurveillanceStation, config.get(CONF_URL), config.get(CONF_USERNAME), config.get(CONF_PASSWORD), verify_ssl=verify_ssl, timeout=timeout, ) ) except (requests.exceptions.RequestException, ValueError): _LOGGER.exception("Error when initializing SurveillanceStation") return False cameras = surveillance.get_all_cameras() # add cameras devices = [] for camera in cameras: if not config[CONF_WHITELIST] or camera.name in config[CONF_WHITELIST]: device = SynologyCamera(surveillance, camera.camera_id, verify_ssl) devices.append(device) async_add_entities(devices)
[ "async", "def", "async_setup_platform", "(", "hass", ",", "config", ",", "async_add_entities", ",", "discovery_info", "=", "None", ")", ":", "_LOGGER", ".", "warning", "(", "\"The Synology integration is deprecated.\"", "\" Please use the Synology DSM integration\"", "\" (https://www.home-assistant.io/integrations/synology_dsm/) instead.\"", "\" This integration will be removed in version 0.118.0.\"", ")", "verify_ssl", "=", "config", ".", "get", "(", "CONF_VERIFY_SSL", ")", "timeout", "=", "config", ".", "get", "(", "CONF_TIMEOUT", ")", "try", ":", "surveillance", "=", "await", "hass", ".", "async_add_executor_job", "(", "partial", "(", "SurveillanceStation", ",", "config", ".", "get", "(", "CONF_URL", ")", ",", "config", ".", "get", "(", "CONF_USERNAME", ")", ",", "config", ".", "get", "(", "CONF_PASSWORD", ")", ",", "verify_ssl", "=", "verify_ssl", ",", "timeout", "=", "timeout", ",", ")", ")", "except", "(", "requests", ".", "exceptions", ".", "RequestException", ",", "ValueError", ")", ":", "_LOGGER", ".", "exception", "(", "\"Error when initializing SurveillanceStation\"", ")", "return", "False", "cameras", "=", "surveillance", ".", "get_all_cameras", "(", ")", "# add cameras", "devices", "=", "[", "]", "for", "camera", "in", "cameras", ":", "if", "not", "config", "[", "CONF_WHITELIST", "]", "or", "camera", ".", "name", "in", "config", "[", "CONF_WHITELIST", "]", ":", "device", "=", "SynologyCamera", "(", "surveillance", ",", "camera", ".", "camera_id", ",", "verify_ssl", ")", "devices", ".", "append", "(", "device", ")", "async_add_entities", "(", "devices", ")" ]
[ 42, 0 ]
[ 78, 31 ]
python
en
['en', 'fil', 'en']
True
SynologyCamera.__init__
(self, surveillance, camera_id, verify_ssl)
Initialize a Synology Surveillance Station camera.
Initialize a Synology Surveillance Station camera.
def __init__(self, surveillance, camera_id, verify_ssl): """Initialize a Synology Surveillance Station camera.""" super().__init__() self._surveillance = surveillance self._camera_id = camera_id self._verify_ssl = verify_ssl self._camera = self._surveillance.get_camera(camera_id) self._motion_setting = self._surveillance.get_motion_setting(camera_id) self.is_streaming = self._camera.is_enabled
[ "def", "__init__", "(", "self", ",", "surveillance", ",", "camera_id", ",", "verify_ssl", ")", ":", "super", "(", ")", ".", "__init__", "(", ")", "self", ".", "_surveillance", "=", "surveillance", "self", ".", "_camera_id", "=", "camera_id", "self", ".", "_verify_ssl", "=", "verify_ssl", "self", ".", "_camera", "=", "self", ".", "_surveillance", ".", "get_camera", "(", "camera_id", ")", "self", ".", "_motion_setting", "=", "self", ".", "_surveillance", ".", "get_motion_setting", "(", "camera_id", ")", "self", ".", "is_streaming", "=", "self", ".", "_camera", ".", "is_enabled" ]
[ 84, 4 ]
[ 92, 51 ]
python
en
['en', 'en', 'en']
True
SynologyCamera.camera_image
(self)
Return bytes of camera image.
Return bytes of camera image.
def camera_image(self): """Return bytes of camera image.""" return self._surveillance.get_camera_image(self._camera_id)
[ "def", "camera_image", "(", "self", ")", ":", "return", "self", ".", "_surveillance", ".", "get_camera_image", "(", "self", ".", "_camera_id", ")" ]
[ 94, 4 ]
[ 96, 67 ]
python
en
['en', 'zu', 'en']
True
SynologyCamera.handle_async_mjpeg_stream
(self, request)
Return a MJPEG stream image response directly from the camera.
Return a MJPEG stream image response directly from the camera.
async def handle_async_mjpeg_stream(self, request): """Return a MJPEG stream image response directly from the camera.""" streaming_url = self._camera.video_stream_url websession = async_get_clientsession(self.hass, self._verify_ssl) stream_coro = websession.get(streaming_url) return await async_aiohttp_proxy_web(self.hass, request, stream_coro)
[ "async", "def", "handle_async_mjpeg_stream", "(", "self", ",", "request", ")", ":", "streaming_url", "=", "self", ".", "_camera", ".", "video_stream_url", "websession", "=", "async_get_clientsession", "(", "self", ".", "hass", ",", "self", ".", "_verify_ssl", ")", "stream_coro", "=", "websession", ".", "get", "(", "streaming_url", ")", "return", "await", "async_aiohttp_proxy_web", "(", "self", ".", "hass", ",", "request", ",", "stream_coro", ")" ]
[ 98, 4 ]
[ 105, 77 ]
python
en
['en', 'en', 'en']
True
SynologyCamera.name
(self)
Return the name of this device.
Return the name of this device.
def name(self): """Return the name of this device.""" return self._camera.name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_camera", ".", "name" ]
[ 108, 4 ]
[ 110, 32 ]
python
en
['en', 'en', 'en']
True
SynologyCamera.is_recording
(self)
Return true if the device is recording.
Return true if the device is recording.
def is_recording(self): """Return true if the device is recording.""" return self._camera.is_recording
[ "def", "is_recording", "(", "self", ")", ":", "return", "self", ".", "_camera", ".", "is_recording" ]
[ 113, 4 ]
[ 115, 40 ]
python
en
['en', 'en', 'en']
True
SynologyCamera.should_poll
(self)
Update the recording state periodically.
Update the recording state periodically.
def should_poll(self): """Update the recording state periodically.""" return True
[ "def", "should_poll", "(", "self", ")", ":", "return", "True" ]
[ 118, 4 ]
[ 120, 19 ]
python
en
['en', 'en', 'en']
True
SynologyCamera.update
(self)
Update the status of the camera.
Update the status of the camera.
def update(self): """Update the status of the camera.""" self._surveillance.update() self._camera = self._surveillance.get_camera(self._camera.camera_id) self._motion_setting = self._surveillance.get_motion_setting( self._camera.camera_id ) self.is_streaming = self._camera.is_enabled
[ "def", "update", "(", "self", ")", ":", "self", ".", "_surveillance", ".", "update", "(", ")", "self", ".", "_camera", "=", "self", ".", "_surveillance", ".", "get_camera", "(", "self", ".", "_camera", ".", "camera_id", ")", "self", ".", "_motion_setting", "=", "self", ".", "_surveillance", ".", "get_motion_setting", "(", "self", ".", "_camera", ".", "camera_id", ")", "self", ".", "is_streaming", "=", "self", ".", "_camera", ".", "is_enabled" ]
[ 122, 4 ]
[ 129, 51 ]
python
en
['en', 'en', 'en']
True
SynologyCamera.motion_detection_enabled
(self)
Return the camera motion detection status.
Return the camera motion detection status.
def motion_detection_enabled(self): """Return the camera motion detection status.""" return self._motion_setting.is_enabled
[ "def", "motion_detection_enabled", "(", "self", ")", ":", "return", "self", ".", "_motion_setting", ".", "is_enabled" ]
[ 132, 4 ]
[ 134, 46 ]
python
en
['en', 'en', 'en']
True
SynologyCamera.enable_motion_detection
(self)
Enable motion detection in the camera.
Enable motion detection in the camera.
def enable_motion_detection(self): """Enable motion detection in the camera.""" self._surveillance.enable_motion_detection(self._camera_id)
[ "def", "enable_motion_detection", "(", "self", ")", ":", "self", ".", "_surveillance", ".", "enable_motion_detection", "(", "self", ".", "_camera_id", ")" ]
[ 136, 4 ]
[ 138, 67 ]
python
en
['en', 'en', 'en']
True
SynologyCamera.disable_motion_detection
(self)
Disable motion detection in camera.
Disable motion detection in camera.
def disable_motion_detection(self): """Disable motion detection in camera.""" self._surveillance.disable_motion_detection(self._camera_id)
[ "def", "disable_motion_detection", "(", "self", ")", ":", "self", ".", "_surveillance", ".", "disable_motion_detection", "(", "self", ".", "_camera_id", ")" ]
[ 140, 4 ]
[ 142, 68 ]
python
en
['it', 'en', 'en']
True
storage_setup
(hass, hass_storage)
Storage setup.
Storage setup.
def storage_setup(hass, hass_storage): """Storage setup.""" async def _storage(items=None): if items is None: hass_storage[DOMAIN] = { "key": DOMAIN, "version": 1, "data": {"items": [{"id": "test tag"}]}, } else: hass_storage[DOMAIN] = items config = {DOMAIN: {}} return await async_setup_component(hass, DOMAIN, config) return _storage
[ "def", "storage_setup", "(", "hass", ",", "hass_storage", ")", ":", "async", "def", "_storage", "(", "items", "=", "None", ")", ":", "if", "items", "is", "None", ":", "hass_storage", "[", "DOMAIN", "]", "=", "{", "\"key\"", ":", "DOMAIN", ",", "\"version\"", ":", "1", ",", "\"data\"", ":", "{", "\"items\"", ":", "[", "{", "\"id\"", ":", "\"test tag\"", "}", "]", "}", ",", "}", "else", ":", "hass_storage", "[", "DOMAIN", "]", "=", "items", "config", "=", "{", "DOMAIN", ":", "{", "}", "}", "return", "await", "async_setup_component", "(", "hass", ",", "DOMAIN", ",", "config", ")", "return", "_storage" ]
[ 12, 0 ]
[ 27, 19 ]
python
en
['en', 'bs', 'en']
False
test_ws_list
(hass, hass_ws_client, storage_setup)
Test listing tags via WS.
Test listing tags via WS.
async def test_ws_list(hass, hass_ws_client, storage_setup): """Test listing tags via WS.""" assert await storage_setup() client = await hass_ws_client(hass) await client.send_json({"id": 6, "type": f"{DOMAIN}/list"}) resp = await client.receive_json() assert resp["success"] result = {item["id"]: item for item in resp["result"]} assert len(result) == 1 assert "test tag" in result
[ "async", "def", "test_ws_list", "(", "hass", ",", "hass_ws_client", ",", "storage_setup", ")", ":", "assert", "await", "storage_setup", "(", ")", "client", "=", "await", "hass_ws_client", "(", "hass", ")", "await", "client", ".", "send_json", "(", "{", "\"id\"", ":", "6", ",", "\"type\"", ":", "f\"{DOMAIN}/list\"", "}", ")", "resp", "=", "await", "client", ".", "receive_json", "(", ")", "assert", "resp", "[", "\"success\"", "]", "result", "=", "{", "item", "[", "\"id\"", "]", ":", "item", "for", "item", "in", "resp", "[", "\"result\"", "]", "}", "assert", "len", "(", "result", ")", "==", "1", "assert", "\"test tag\"", "in", "result" ]
[ 30, 0 ]
[ 43, 31 ]
python
en
['en', 'hmn', 'en']
True
test_ws_update
(hass, hass_ws_client, storage_setup)
Test listing tags via WS.
Test listing tags via WS.
async def test_ws_update(hass, hass_ws_client, storage_setup): """Test listing tags via WS.""" assert await storage_setup() await async_scan_tag(hass, "test tag", "some_scanner") client = await hass_ws_client(hass) await client.send_json( { "id": 6, "type": f"{DOMAIN}/update", f"{DOMAIN}_id": "test tag", "name": "New name", } ) resp = await client.receive_json() assert resp["success"] item = resp["result"] assert item["id"] == "test tag" assert item["name"] == "New name"
[ "async", "def", "test_ws_update", "(", "hass", ",", "hass_ws_client", ",", "storage_setup", ")", ":", "assert", "await", "storage_setup", "(", ")", "await", "async_scan_tag", "(", "hass", ",", "\"test tag\"", ",", "\"some_scanner\"", ")", "client", "=", "await", "hass_ws_client", "(", "hass", ")", "await", "client", ".", "send_json", "(", "{", "\"id\"", ":", "6", ",", "\"type\"", ":", "f\"{DOMAIN}/update\"", ",", "f\"{DOMAIN}_id\"", ":", "\"test tag\"", ",", "\"name\"", ":", "\"New name\"", ",", "}", ")", "resp", "=", "await", "client", ".", "receive_json", "(", ")", "assert", "resp", "[", "\"success\"", "]", "item", "=", "resp", "[", "\"result\"", "]", "assert", "item", "[", "\"id\"", "]", "==", "\"test tag\"", "assert", "item", "[", "\"name\"", "]", "==", "\"New name\"" ]
[ 46, 0 ]
[ 67, 37 ]
python
en
['en', 'hmn', 'en']
True
test_tag_scanned
(hass, hass_ws_client, storage_setup)
Test scanning tags.
Test scanning tags.
async def test_tag_scanned(hass, hass_ws_client, storage_setup): """Test scanning tags.""" assert await storage_setup() client = await hass_ws_client(hass) await client.send_json({"id": 6, "type": f"{DOMAIN}/list"}) resp = await client.receive_json() assert resp["success"] result = {item["id"]: item for item in resp["result"]} assert len(result) == 1 assert "test tag" in result now = dt_util.utcnow() with patch("homeassistant.util.dt.utcnow", return_value=now): await async_scan_tag(hass, "new tag", "some_scanner") await client.send_json({"id": 7, "type": f"{DOMAIN}/list"}) resp = await client.receive_json() assert resp["success"] result = {item["id"]: item for item in resp["result"]} assert len(result) == 2 assert "test tag" in result assert "new tag" in result assert result["new tag"]["last_scanned"] == now.isoformat()
[ "async", "def", "test_tag_scanned", "(", "hass", ",", "hass_ws_client", ",", "storage_setup", ")", ":", "assert", "await", "storage_setup", "(", ")", "client", "=", "await", "hass_ws_client", "(", "hass", ")", "await", "client", ".", "send_json", "(", "{", "\"id\"", ":", "6", ",", "\"type\"", ":", "f\"{DOMAIN}/list\"", "}", ")", "resp", "=", "await", "client", ".", "receive_json", "(", ")", "assert", "resp", "[", "\"success\"", "]", "result", "=", "{", "item", "[", "\"id\"", "]", ":", "item", "for", "item", "in", "resp", "[", "\"result\"", "]", "}", "assert", "len", "(", "result", ")", "==", "1", "assert", "\"test tag\"", "in", "result", "now", "=", "dt_util", ".", "utcnow", "(", ")", "with", "patch", "(", "\"homeassistant.util.dt.utcnow\"", ",", "return_value", "=", "now", ")", ":", "await", "async_scan_tag", "(", "hass", ",", "\"new tag\"", ",", "\"some_scanner\"", ")", "await", "client", ".", "send_json", "(", "{", "\"id\"", ":", "7", ",", "\"type\"", ":", "f\"{DOMAIN}/list\"", "}", ")", "resp", "=", "await", "client", ".", "receive_json", "(", ")", "assert", "resp", "[", "\"success\"", "]", "result", "=", "{", "item", "[", "\"id\"", "]", ":", "item", "for", "item", "in", "resp", "[", "\"result\"", "]", "}", "assert", "len", "(", "result", ")", "==", "2", "assert", "\"test tag\"", "in", "result", "assert", "\"new tag\"", "in", "result", "assert", "result", "[", "\"new tag\"", "]", "[", "\"last_scanned\"", "]", "==", "now", ".", "isoformat", "(", ")" ]
[ 70, 0 ]
[ 98, 63 ]
python
en
['en', 'en', 'en']
True
track_changes
(coll: collection.ObservableCollection)
Create helper to track changes in a collection.
Create helper to track changes in a collection.
def track_changes(coll: collection.ObservableCollection): """Create helper to track changes in a collection.""" changes = [] async def listener(*args): changes.append(args) coll.async_add_listener(listener) return changes
[ "def", "track_changes", "(", "coll", ":", "collection", ".", "ObservableCollection", ")", ":", "changes", "=", "[", "]", "async", "def", "listener", "(", "*", "args", ")", ":", "changes", ".", "append", "(", "args", ")", "coll", ".", "async_add_listener", "(", "listener", ")", "return", "changes" ]
[ 101, 0 ]
[ 110, 18 ]
python
en
['en', 'en', 'en']
True
test_tag_id_exists
(hass, hass_ws_client, storage_setup)
Test scanning tags.
Test scanning tags.
async def test_tag_id_exists(hass, hass_ws_client, storage_setup): """Test scanning tags.""" assert await storage_setup() changes = track_changes(hass.data[DOMAIN][TAGS]) client = await hass_ws_client(hass) await client.send_json({"id": 2, "type": f"{DOMAIN}/create", "tag_id": "test tag"}) response = await client.receive_json() assert not response["success"] assert response["error"]["code"] == "unknown_error" assert len(changes) == 0
[ "async", "def", "test_tag_id_exists", "(", "hass", ",", "hass_ws_client", ",", "storage_setup", ")", ":", "assert", "await", "storage_setup", "(", ")", "changes", "=", "track_changes", "(", "hass", ".", "data", "[", "DOMAIN", "]", "[", "TAGS", "]", ")", "client", "=", "await", "hass_ws_client", "(", "hass", ")", "await", "client", ".", "send_json", "(", "{", "\"id\"", ":", "2", ",", "\"type\"", ":", "f\"{DOMAIN}/create\"", ",", "\"tag_id\"", ":", "\"test tag\"", "}", ")", "response", "=", "await", "client", ".", "receive_json", "(", ")", "assert", "not", "response", "[", "\"success\"", "]", "assert", "response", "[", "\"error\"", "]", "[", "\"code\"", "]", "==", "\"unknown_error\"", "assert", "len", "(", "changes", ")", "==", "0" ]
[ 113, 0 ]
[ 123, 28 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
( hass: HomeAssistantType, config: ConfigType, async_add_entities )
Initialize an IZone Controller.
Initialize an IZone Controller.
async def async_setup_entry( hass: HomeAssistantType, config: ConfigType, async_add_entities ): """Initialize an IZone Controller.""" disco = hass.data[DATA_DISCOVERY_SERVICE] @callback def init_controller(ctrl: Controller): """Register the controller device and the containing zones.""" conf = hass.data.get(DATA_CONFIG) # type: ConfigType # Filter out any entities excluded in the config file if conf and ctrl.device_uid in conf[CONF_EXCLUDE]: _LOGGER.info("Controller UID=%s ignored as excluded", ctrl.device_uid) return _LOGGER.info("Controller UID=%s discovered", ctrl.device_uid) device = ControllerDevice(ctrl) async_add_entities([device]) async_add_entities(device.zones.values()) # create any components not yet created for controller in disco.pi_disco.controllers.values(): init_controller(controller) # connect to register any further components async_dispatcher_connect(hass, DISPATCH_CONTROLLER_DISCOVERED, init_controller) return True
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistantType", ",", "config", ":", "ConfigType", ",", "async_add_entities", ")", ":", "disco", "=", "hass", ".", "data", "[", "DATA_DISCOVERY_SERVICE", "]", "@", "callback", "def", "init_controller", "(", "ctrl", ":", "Controller", ")", ":", "\"\"\"Register the controller device and the containing zones.\"\"\"", "conf", "=", "hass", ".", "data", ".", "get", "(", "DATA_CONFIG", ")", "# type: ConfigType", "# Filter out any entities excluded in the config file", "if", "conf", "and", "ctrl", ".", "device_uid", "in", "conf", "[", "CONF_EXCLUDE", "]", ":", "_LOGGER", ".", "info", "(", "\"Controller UID=%s ignored as excluded\"", ",", "ctrl", ".", "device_uid", ")", "return", "_LOGGER", ".", "info", "(", "\"Controller UID=%s discovered\"", ",", "ctrl", ".", "device_uid", ")", "device", "=", "ControllerDevice", "(", "ctrl", ")", "async_add_entities", "(", "[", "device", "]", ")", "async_add_entities", "(", "device", ".", "zones", ".", "values", "(", ")", ")", "# create any components not yet created", "for", "controller", "in", "disco", ".", "pi_disco", ".", "controllers", ".", "values", "(", ")", ":", "init_controller", "(", "controller", ")", "# connect to register any further components", "async_dispatcher_connect", "(", "hass", ",", "DISPATCH_CONTROLLER_DISCOVERED", ",", "init_controller", ")", "return", "True" ]
[ 57, 0 ]
[ 85, 15 ]
python
co
['en', 'co', 'it']
False
ControllerDevice.__init__
(self, controller: Controller)
Initialise ControllerDevice.
Initialise ControllerDevice.
def __init__(self, controller: Controller) -> None: """Initialise ControllerDevice.""" self._controller = controller self._supported_features = SUPPORT_FAN_MODE if ( controller.ras_mode == "master" and controller.zone_ctrl == 13 ) or controller.ras_mode == "RAS": self._supported_features |= SUPPORT_TARGET_TEMPERATURE self._state_to_pizone = { HVAC_MODE_COOL: Controller.Mode.COOL, HVAC_MODE_HEAT: Controller.Mode.HEAT, HVAC_MODE_HEAT_COOL: Controller.Mode.AUTO, HVAC_MODE_FAN_ONLY: Controller.Mode.VENT, HVAC_MODE_DRY: Controller.Mode.DRY, } if controller.free_air_enabled: self._supported_features |= SUPPORT_PRESET_MODE self._fan_to_pizone = {} for fan in controller.fan_modes: self._fan_to_pizone[_IZONE_FAN_TO_HA[fan]] = fan self._available = True self._device_info = { "identifiers": {(IZONE, self.unique_id)}, "name": self.name, "manufacturer": "IZone", "model": self._controller.sys_type, } # Create the zones self.zones = {} for zone in controller.zones: self.zones[zone] = ZoneDevice(self, zone)
[ "def", "__init__", "(", "self", ",", "controller", ":", "Controller", ")", "->", "None", ":", "self", ".", "_controller", "=", "controller", "self", ".", "_supported_features", "=", "SUPPORT_FAN_MODE", "if", "(", "controller", ".", "ras_mode", "==", "\"master\"", "and", "controller", ".", "zone_ctrl", "==", "13", ")", "or", "controller", ".", "ras_mode", "==", "\"RAS\"", ":", "self", ".", "_supported_features", "|=", "SUPPORT_TARGET_TEMPERATURE", "self", ".", "_state_to_pizone", "=", "{", "HVAC_MODE_COOL", ":", "Controller", ".", "Mode", ".", "COOL", ",", "HVAC_MODE_HEAT", ":", "Controller", ".", "Mode", ".", "HEAT", ",", "HVAC_MODE_HEAT_COOL", ":", "Controller", ".", "Mode", ".", "AUTO", ",", "HVAC_MODE_FAN_ONLY", ":", "Controller", ".", "Mode", ".", "VENT", ",", "HVAC_MODE_DRY", ":", "Controller", ".", "Mode", ".", "DRY", ",", "}", "if", "controller", ".", "free_air_enabled", ":", "self", ".", "_supported_features", "|=", "SUPPORT_PRESET_MODE", "self", ".", "_fan_to_pizone", "=", "{", "}", "for", "fan", "in", "controller", ".", "fan_modes", ":", "self", ".", "_fan_to_pizone", "[", "_IZONE_FAN_TO_HA", "[", "fan", "]", "]", "=", "fan", "self", ".", "_available", "=", "True", "self", ".", "_device_info", "=", "{", "\"identifiers\"", ":", "{", "(", "IZONE", ",", "self", ".", "unique_id", ")", "}", ",", "\"name\"", ":", "self", ".", "name", ",", "\"manufacturer\"", ":", "\"IZone\"", ",", "\"model\"", ":", "self", ".", "_controller", ".", "sys_type", ",", "}", "# Create the zones", "self", ".", "zones", "=", "{", "}", "for", "zone", "in", "controller", ".", "zones", ":", "self", ".", "zones", "[", "zone", "]", "=", "ZoneDevice", "(", "self", ",", "zone", ")" ]
[ 106, 4 ]
[ 142, 53 ]
python
en
['et', 'en', 'it']
False
ControllerDevice.async_added_to_hass
(self)
Call on adding to hass.
Call on adding to hass.
async def async_added_to_hass(self): """Call on adding to hass.""" # Register for connect/disconnect/update events @callback def controller_disconnected(ctrl: Controller, ex: Exception) -> None: """Disconnected from controller.""" if ctrl is not self._controller: return self.set_available(False, ex) self.async_on_remove( async_dispatcher_connect( self.hass, DISPATCH_CONTROLLER_DISCONNECTED, controller_disconnected ) ) @callback def controller_reconnected(ctrl: Controller) -> None: """Reconnected to controller.""" if ctrl is not self._controller: return self.set_available(True) self.async_on_remove( async_dispatcher_connect( self.hass, DISPATCH_CONTROLLER_RECONNECTED, controller_reconnected ) ) @callback def controller_update(ctrl: Controller) -> None: """Handle controller data updates.""" if ctrl is not self._controller: return self.async_write_ha_state() for zone in self.zones.values(): zone.async_schedule_update_ha_state() self.async_on_remove( async_dispatcher_connect( self.hass, DISPATCH_CONTROLLER_UPDATE, controller_update ) )
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "# Register for connect/disconnect/update events", "@", "callback", "def", "controller_disconnected", "(", "ctrl", ":", "Controller", ",", "ex", ":", "Exception", ")", "->", "None", ":", "\"\"\"Disconnected from controller.\"\"\"", "if", "ctrl", "is", "not", "self", ".", "_controller", ":", "return", "self", ".", "set_available", "(", "False", ",", "ex", ")", "self", ".", "async_on_remove", "(", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "DISPATCH_CONTROLLER_DISCONNECTED", ",", "controller_disconnected", ")", ")", "@", "callback", "def", "controller_reconnected", "(", "ctrl", ":", "Controller", ")", "->", "None", ":", "\"\"\"Reconnected to controller.\"\"\"", "if", "ctrl", "is", "not", "self", ".", "_controller", ":", "return", "self", ".", "set_available", "(", "True", ")", "self", ".", "async_on_remove", "(", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "DISPATCH_CONTROLLER_RECONNECTED", ",", "controller_reconnected", ")", ")", "@", "callback", "def", "controller_update", "(", "ctrl", ":", "Controller", ")", "->", "None", ":", "\"\"\"Handle controller data updates.\"\"\"", "if", "ctrl", "is", "not", "self", ".", "_controller", ":", "return", "self", ".", "async_write_ha_state", "(", ")", "for", "zone", "in", "self", ".", "zones", ".", "values", "(", ")", ":", "zone", ".", "async_schedule_update_ha_state", "(", ")", "self", ".", "async_on_remove", "(", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "DISPATCH_CONTROLLER_UPDATE", ",", "controller_update", ")", ")" ]
[ 144, 4 ]
[ 186, 9 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.available
(self)
Return True if entity is available.
Return True if entity is available.
def available(self) -> bool: """Return True if entity is available.""" return self._available
[ "def", "available", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_available" ]
[ 189, 4 ]
[ 191, 30 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.set_available
(self, available: bool, ex: Exception = None)
Set availability for the controller. Also sets zone availability as they follow the same availability.
Set availability for the controller.
def set_available(self, available: bool, ex: Exception = None) -> None: """ Set availability for the controller. Also sets zone availability as they follow the same availability. """ if self.available == available: return if available: _LOGGER.info("Reconnected controller %s ", self._controller.device_uid) else: _LOGGER.info( "Controller %s disconnected due to exception: %s", self._controller.device_uid, ex, ) self._available = available self.async_write_ha_state() for zone in self.zones.values(): zone.async_schedule_update_ha_state()
[ "def", "set_available", "(", "self", ",", "available", ":", "bool", ",", "ex", ":", "Exception", "=", "None", ")", "->", "None", ":", "if", "self", ".", "available", "==", "available", ":", "return", "if", "available", ":", "_LOGGER", ".", "info", "(", "\"Reconnected controller %s \"", ",", "self", ".", "_controller", ".", "device_uid", ")", "else", ":", "_LOGGER", ".", "info", "(", "\"Controller %s disconnected due to exception: %s\"", ",", "self", ".", "_controller", ".", "device_uid", ",", "ex", ",", ")", "self", ".", "_available", "=", "available", "self", ".", "async_write_ha_state", "(", ")", "for", "zone", "in", "self", ".", "zones", ".", "values", "(", ")", ":", "zone", ".", "async_schedule_update_ha_state", "(", ")" ]
[ 194, 4 ]
[ 215, 49 ]
python
en
['en', 'error', 'th']
False
ControllerDevice.device_info
(self)
Return the device info for the iZone system.
Return the device info for the iZone system.
def device_info(self): """Return the device info for the iZone system.""" return self._device_info
[ "def", "device_info", "(", "self", ")", ":", "return", "self", ".", "_device_info" ]
[ 218, 4 ]
[ 220, 32 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.unique_id
(self)
Return the ID of the controller device.
Return the ID of the controller device.
def unique_id(self): """Return the ID of the controller device.""" return self._controller.device_uid
[ "def", "unique_id", "(", "self", ")", ":", "return", "self", ".", "_controller", ".", "device_uid" ]
[ 223, 4 ]
[ 225, 42 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.name
(self)
Return the name of the entity.
Return the name of the entity.
def name(self) -> str: """Return the name of the entity.""" return f"iZone Controller {self._controller.device_uid}"
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "f\"iZone Controller {self._controller.device_uid}\"" ]
[ 228, 4 ]
[ 230, 64 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.should_poll
(self)
Return True if entity has to be polled for state. False if entity pushes its state to HA.
Return True if entity has to be polled for state.
def should_poll(self) -> bool: """Return True if entity has to be polled for state. False if entity pushes its state to HA. """ return False
[ "def", "should_poll", "(", "self", ")", "->", "bool", ":", "return", "False" ]
[ 233, 4 ]
[ 238, 20 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.supported_features
(self)
Return the list of supported features.
Return the list of supported features.
def supported_features(self) -> int: """Return the list of supported features.""" return self._supported_features
[ "def", "supported_features", "(", "self", ")", "->", "int", ":", "return", "self", ".", "_supported_features" ]
[ 241, 4 ]
[ 243, 39 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.temperature_unit
(self)
Return the unit of measurement which this thermostat uses.
Return the unit of measurement which this thermostat uses.
def temperature_unit(self) -> str: """Return the unit of measurement which this thermostat uses.""" return TEMP_CELSIUS
[ "def", "temperature_unit", "(", "self", ")", "->", "str", ":", "return", "TEMP_CELSIUS" ]
[ 246, 4 ]
[ 248, 27 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.precision
(self)
Return the precision of the system.
Return the precision of the system.
def precision(self) -> float: """Return the precision of the system.""" return PRECISION_TENTHS
[ "def", "precision", "(", "self", ")", "->", "float", ":", "return", "PRECISION_TENTHS" ]
[ 251, 4 ]
[ 253, 31 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.device_state_attributes
(self)
Return the optional state attributes.
Return the optional state attributes.
def device_state_attributes(self): """Return the optional state attributes.""" return { "supply_temperature": show_temp( self.hass, self.supply_temperature, self.temperature_unit, self.precision, ), "temp_setpoint": show_temp( self.hass, self._controller.temp_setpoint, self.temperature_unit, PRECISION_HALVES, ), }
[ "def", "device_state_attributes", "(", "self", ")", ":", "return", "{", "\"supply_temperature\"", ":", "show_temp", "(", "self", ".", "hass", ",", "self", ".", "supply_temperature", ",", "self", ".", "temperature_unit", ",", "self", ".", "precision", ",", ")", ",", "\"temp_setpoint\"", ":", "show_temp", "(", "self", ".", "hass", ",", "self", ".", "_controller", ".", "temp_setpoint", ",", "self", ".", "temperature_unit", ",", "PRECISION_HALVES", ",", ")", ",", "}" ]
[ 256, 4 ]
[ 271, 9 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.hvac_mode
(self)
Return current operation ie. heat, cool, idle.
Return current operation ie. heat, cool, idle.
def hvac_mode(self) -> str: """Return current operation ie. heat, cool, idle.""" if not self._controller.is_on: return HVAC_MODE_OFF mode = self._controller.mode if mode == Controller.Mode.FREE_AIR: return HVAC_MODE_FAN_ONLY for (key, value) in self._state_to_pizone.items(): if value == mode: return key assert False, "Should be unreachable"
[ "def", "hvac_mode", "(", "self", ")", "->", "str", ":", "if", "not", "self", ".", "_controller", ".", "is_on", ":", "return", "HVAC_MODE_OFF", "mode", "=", "self", ".", "_controller", ".", "mode", "if", "mode", "==", "Controller", ".", "Mode", ".", "FREE_AIR", ":", "return", "HVAC_MODE_FAN_ONLY", "for", "(", "key", ",", "value", ")", "in", "self", ".", "_state_to_pizone", ".", "items", "(", ")", ":", "if", "value", "==", "mode", ":", "return", "key", "assert", "False", ",", "\"Should be unreachable\"" ]
[ 274, 4 ]
[ 284, 45 ]
python
en
['nl', 'en', 'en']
True
ControllerDevice.hvac_modes
(self)
Return the list of available operation modes.
Return the list of available operation modes.
def hvac_modes(self) -> List[str]: """Return the list of available operation modes.""" if self._controller.free_air: return [HVAC_MODE_OFF, HVAC_MODE_FAN_ONLY] return [HVAC_MODE_OFF, *self._state_to_pizone]
[ "def", "hvac_modes", "(", "self", ")", "->", "List", "[", "str", "]", ":", "if", "self", ".", "_controller", ".", "free_air", ":", "return", "[", "HVAC_MODE_OFF", ",", "HVAC_MODE_FAN_ONLY", "]", "return", "[", "HVAC_MODE_OFF", ",", "*", "self", ".", "_state_to_pizone", "]" ]
[ 288, 4 ]
[ 292, 54 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.preset_mode
(self)
Eco mode is external air.
Eco mode is external air.
def preset_mode(self): """Eco mode is external air.""" return PRESET_ECO if self._controller.free_air else PRESET_NONE
[ "def", "preset_mode", "(", "self", ")", ":", "return", "PRESET_ECO", "if", "self", ".", "_controller", ".", "free_air", "else", "PRESET_NONE" ]
[ 296, 4 ]
[ 298, 71 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.preset_modes
(self)
Available preset modes, normal or eco.
Available preset modes, normal or eco.
def preset_modes(self): """Available preset modes, normal or eco.""" if self._controller.free_air_enabled: return [PRESET_NONE, PRESET_ECO] return [PRESET_NONE]
[ "def", "preset_modes", "(", "self", ")", ":", "if", "self", ".", "_controller", ".", "free_air_enabled", ":", "return", "[", "PRESET_NONE", ",", "PRESET_ECO", "]", "return", "[", "PRESET_NONE", "]" ]
[ 302, 4 ]
[ 306, 28 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.current_temperature
(self)
Return the current temperature.
Return the current temperature.
def current_temperature(self) -> Optional[float]: """Return the current temperature.""" if self._controller.mode == Controller.Mode.FREE_AIR: return self._controller.temp_supply return self._controller.temp_return
[ "def", "current_temperature", "(", "self", ")", "->", "Optional", "[", "float", "]", ":", "if", "self", ".", "_controller", ".", "mode", "==", "Controller", ".", "Mode", ".", "FREE_AIR", ":", "return", "self", ".", "_controller", ".", "temp_supply", "return", "self", ".", "_controller", ".", "temp_return" ]
[ 310, 4 ]
[ 314, 43 ]
python
en
['en', 'la', 'en']
True
ControllerDevice.target_temperature
(self)
Return the temperature we try to reach.
Return the temperature we try to reach.
def target_temperature(self) -> Optional[float]: """Return the temperature we try to reach.""" if not self._supported_features & SUPPORT_TARGET_TEMPERATURE: return None return self._controller.temp_setpoint
[ "def", "target_temperature", "(", "self", ")", "->", "Optional", "[", "float", "]", ":", "if", "not", "self", ".", "_supported_features", "&", "SUPPORT_TARGET_TEMPERATURE", ":", "return", "None", "return", "self", ".", "_controller", ".", "temp_setpoint" ]
[ 318, 4 ]
[ 322, 45 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.supply_temperature
(self)
Return the current supply, or in duct, temperature.
Return the current supply, or in duct, temperature.
def supply_temperature(self) -> float: """Return the current supply, or in duct, temperature.""" return self._controller.temp_supply
[ "def", "supply_temperature", "(", "self", ")", "->", "float", ":", "return", "self", ".", "_controller", ".", "temp_supply" ]
[ 325, 4 ]
[ 327, 43 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.target_temperature_step
(self)
Return the supported step of target temperature.
Return the supported step of target temperature.
def target_temperature_step(self) -> Optional[float]: """Return the supported step of target temperature.""" return 0.5
[ "def", "target_temperature_step", "(", "self", ")", "->", "Optional", "[", "float", "]", ":", "return", "0.5" ]
[ 330, 4 ]
[ 332, 18 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.fan_mode
(self)
Return the fan setting.
Return the fan setting.
def fan_mode(self) -> Optional[str]: """Return the fan setting.""" return _IZONE_FAN_TO_HA[self._controller.fan]
[ "def", "fan_mode", "(", "self", ")", "->", "Optional", "[", "str", "]", ":", "return", "_IZONE_FAN_TO_HA", "[", "self", ".", "_controller", ".", "fan", "]" ]
[ 335, 4 ]
[ 337, 53 ]
python
en
['en', 'fy', 'en']
True
ControllerDevice.fan_modes
(self)
Return the list of available fan modes.
Return the list of available fan modes.
def fan_modes(self) -> Optional[List[str]]: """Return the list of available fan modes.""" return list(self._fan_to_pizone)
[ "def", "fan_modes", "(", "self", ")", "->", "Optional", "[", "List", "[", "str", "]", "]", ":", "return", "list", "(", "self", ".", "_fan_to_pizone", ")" ]
[ 340, 4 ]
[ 342, 40 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.min_temp
(self)
Return the minimum temperature.
Return the minimum temperature.
def min_temp(self) -> float: """Return the minimum temperature.""" return self._controller.temp_min
[ "def", "min_temp", "(", "self", ")", "->", "float", ":", "return", "self", ".", "_controller", ".", "temp_min" ]
[ 346, 4 ]
[ 348, 40 ]
python
en
['en', 'la', 'en']
True
ControllerDevice.max_temp
(self)
Return the maximum temperature.
Return the maximum temperature.
def max_temp(self) -> float: """Return the maximum temperature.""" return self._controller.temp_max
[ "def", "max_temp", "(", "self", ")", "->", "float", ":", "return", "self", ".", "_controller", ".", "temp_max" ]
[ 352, 4 ]
[ 354, 40 ]
python
en
['en', 'la', 'en']
True
ControllerDevice.wrap_and_catch
(self, coro)
Catch any connection errors and set unavailable.
Catch any connection errors and set unavailable.
async def wrap_and_catch(self, coro): """Catch any connection errors and set unavailable.""" try: await coro except ConnectionError as ex: self.set_available(False, ex) else: self.set_available(True)
[ "async", "def", "wrap_and_catch", "(", "self", ",", "coro", ")", ":", "try", ":", "await", "coro", "except", "ConnectionError", "as", "ex", ":", "self", ".", "set_available", "(", "False", ",", "ex", ")", "else", ":", "self", ".", "set_available", "(", "True", ")" ]
[ 356, 4 ]
[ 363, 36 ]
python
en
['en', 'en', 'en']
True
ControllerDevice.async_set_temperature
(self, **kwargs)
Set new target temperature.
Set new target temperature.
async def async_set_temperature(self, **kwargs) -> None: """Set new target temperature.""" if not self.supported_features & SUPPORT_TARGET_TEMPERATURE: self.async_schedule_update_ha_state(True) return temp = kwargs.get(ATTR_TEMPERATURE) if temp is not None: await self.wrap_and_catch(self._controller.set_temp_setpoint(temp))
[ "async", "def", "async_set_temperature", "(", "self", ",", "*", "*", "kwargs", ")", "->", "None", ":", "if", "not", "self", ".", "supported_features", "&", "SUPPORT_TARGET_TEMPERATURE", ":", "self", ".", "async_schedule_update_ha_state", "(", "True", ")", "return", "temp", "=", "kwargs", ".", "get", "(", "ATTR_TEMPERATURE", ")", "if", "temp", "is", "not", "None", ":", "await", "self", ".", "wrap_and_catch", "(", "self", ".", "_controller", ".", "set_temp_setpoint", "(", "temp", ")", ")" ]
[ 365, 4 ]
[ 372, 79 ]
python
en
['en', 'ca', 'en']
True
ControllerDevice.async_set_fan_mode
(self, fan_mode: str)
Set new target fan mode.
Set new target fan mode.
async def async_set_fan_mode(self, fan_mode: str) -> None: """Set new target fan mode.""" fan = self._fan_to_pizone[fan_mode] await self.wrap_and_catch(self._controller.set_fan(fan))
[ "async", "def", "async_set_fan_mode", "(", "self", ",", "fan_mode", ":", "str", ")", "->", "None", ":", "fan", "=", "self", ".", "_fan_to_pizone", "[", "fan_mode", "]", "await", "self", ".", "wrap_and_catch", "(", "self", ".", "_controller", ".", "set_fan", "(", "fan", ")", ")" ]
[ 374, 4 ]
[ 377, 64 ]
python
en
['sv', 'fy', 'en']
False
ControllerDevice.async_set_hvac_mode
(self, hvac_mode: str)
Set new target operation mode.
Set new target operation mode.
async def async_set_hvac_mode(self, hvac_mode: str) -> None: """Set new target operation mode.""" if hvac_mode == HVAC_MODE_OFF: await self.wrap_and_catch(self._controller.set_on(False)) return if not self._controller.is_on: await self.wrap_and_catch(self._controller.set_on(True)) if self._controller.free_air: return mode = self._state_to_pizone[hvac_mode] await self.wrap_and_catch(self._controller.set_mode(mode))
[ "async", "def", "async_set_hvac_mode", "(", "self", ",", "hvac_mode", ":", "str", ")", "->", "None", ":", "if", "hvac_mode", "==", "HVAC_MODE_OFF", ":", "await", "self", ".", "wrap_and_catch", "(", "self", ".", "_controller", ".", "set_on", "(", "False", ")", ")", "return", "if", "not", "self", ".", "_controller", ".", "is_on", ":", "await", "self", ".", "wrap_and_catch", "(", "self", ".", "_controller", ".", "set_on", "(", "True", ")", ")", "if", "self", ".", "_controller", ".", "free_air", ":", "return", "mode", "=", "self", ".", "_state_to_pizone", "[", "hvac_mode", "]", "await", "self", ".", "wrap_and_catch", "(", "self", ".", "_controller", ".", "set_mode", "(", "mode", ")", ")" ]
[ 379, 4 ]
[ 389, 66 ]
python
en
['nl', 'en', 'en']
True
ControllerDevice.async_set_preset_mode
(self, preset_mode: str)
Set the preset mode.
Set the preset mode.
async def async_set_preset_mode(self, preset_mode: str) -> None: """Set the preset mode.""" await self.wrap_and_catch( self._controller.set_free_air(preset_mode == PRESET_ECO) )
[ "async", "def", "async_set_preset_mode", "(", "self", ",", "preset_mode", ":", "str", ")", "->", "None", ":", "await", "self", ".", "wrap_and_catch", "(", "self", ".", "_controller", ".", "set_free_air", "(", "preset_mode", "==", "PRESET_ECO", ")", ")" ]
[ 391, 4 ]
[ 395, 9 ]
python
en
['en', 'pt', 'en']
True
ControllerDevice.async_turn_on
(self)
Turn the entity on.
Turn the entity on.
async def async_turn_on(self) -> None: """Turn the entity on.""" await self.wrap_and_catch(self._controller.set_on(True))
[ "async", "def", "async_turn_on", "(", "self", ")", "->", "None", ":", "await", "self", ".", "wrap_and_catch", "(", "self", ".", "_controller", ".", "set_on", "(", "True", ")", ")" ]
[ 397, 4 ]
[ 399, 64 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.__init__
(self, controller: ControllerDevice, zone: Zone)
Initialise ZoneDevice.
Initialise ZoneDevice.
def __init__(self, controller: ControllerDevice, zone: Zone) -> None: """Initialise ZoneDevice.""" self._controller = controller self._zone = zone self._name = zone.name.title() self._supported_features = 0 if zone.type != Zone.Type.AUTO: self._state_to_pizone = { HVAC_MODE_OFF: Zone.Mode.CLOSE, HVAC_MODE_FAN_ONLY: Zone.Mode.OPEN, } else: self._state_to_pizone = { HVAC_MODE_OFF: Zone.Mode.CLOSE, HVAC_MODE_FAN_ONLY: Zone.Mode.OPEN, HVAC_MODE_HEAT_COOL: Zone.Mode.AUTO, } self._supported_features |= SUPPORT_TARGET_TEMPERATURE self._device_info = { "identifiers": {(IZONE, controller.unique_id, zone.index)}, "name": self.name, "manufacturer": "IZone", "via_device": (IZONE, controller.unique_id), "model": zone.type.name.title(), }
[ "def", "__init__", "(", "self", ",", "controller", ":", "ControllerDevice", ",", "zone", ":", "Zone", ")", "->", "None", ":", "self", ".", "_controller", "=", "controller", "self", ".", "_zone", "=", "zone", "self", ".", "_name", "=", "zone", ".", "name", ".", "title", "(", ")", "self", ".", "_supported_features", "=", "0", "if", "zone", ".", "type", "!=", "Zone", ".", "Type", ".", "AUTO", ":", "self", ".", "_state_to_pizone", "=", "{", "HVAC_MODE_OFF", ":", "Zone", ".", "Mode", ".", "CLOSE", ",", "HVAC_MODE_FAN_ONLY", ":", "Zone", ".", "Mode", ".", "OPEN", ",", "}", "else", ":", "self", ".", "_state_to_pizone", "=", "{", "HVAC_MODE_OFF", ":", "Zone", ".", "Mode", ".", "CLOSE", ",", "HVAC_MODE_FAN_ONLY", ":", "Zone", ".", "Mode", ".", "OPEN", ",", "HVAC_MODE_HEAT_COOL", ":", "Zone", ".", "Mode", ".", "AUTO", ",", "}", "self", ".", "_supported_features", "|=", "SUPPORT_TARGET_TEMPERATURE", "self", ".", "_device_info", "=", "{", "\"identifiers\"", ":", "{", "(", "IZONE", ",", "controller", ".", "unique_id", ",", "zone", ".", "index", ")", "}", ",", "\"name\"", ":", "self", ".", "name", ",", "\"manufacturer\"", ":", "\"IZone\"", ",", "\"via_device\"", ":", "(", "IZONE", ",", "controller", ".", "unique_id", ")", ",", "\"model\"", ":", "zone", ".", "type", ".", "name", ".", "title", "(", ")", ",", "}" ]
[ 405, 4 ]
[ 431, 9 ]
python
en
['et', 'en', 'it']
False
ZoneDevice.async_added_to_hass
(self)
Call on adding to hass.
Call on adding to hass.
async def async_added_to_hass(self): """Call on adding to hass.""" @callback def zone_update(ctrl: Controller, zone: Zone) -> None: """Handle zone data updates.""" if zone is not self._zone: return self._name = zone.name.title() self.async_write_ha_state() self.async_on_remove( async_dispatcher_connect(self.hass, DISPATCH_ZONE_UPDATE, zone_update) )
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "@", "callback", "def", "zone_update", "(", "ctrl", ":", "Controller", ",", "zone", ":", "Zone", ")", "->", "None", ":", "\"\"\"Handle zone data updates.\"\"\"", "if", "zone", "is", "not", "self", ".", "_zone", ":", "return", "self", ".", "_name", "=", "zone", ".", "name", ".", "title", "(", ")", "self", ".", "async_write_ha_state", "(", ")", "self", ".", "async_on_remove", "(", "async_dispatcher_connect", "(", "self", ".", "hass", ",", "DISPATCH_ZONE_UPDATE", ",", "zone_update", ")", ")" ]
[ 433, 4 ]
[ 446, 9 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.available
(self)
Return True if entity is available.
Return True if entity is available.
def available(self) -> bool: """Return True if entity is available.""" return self._controller.available
[ "def", "available", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_controller", ".", "available" ]
[ 449, 4 ]
[ 451, 41 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.assumed_state
(self)
Return True if unable to access real state of the entity.
Return True if unable to access real state of the entity.
def assumed_state(self) -> bool: """Return True if unable to access real state of the entity.""" return self._controller.assumed_state
[ "def", "assumed_state", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_controller", ".", "assumed_state" ]
[ 454, 4 ]
[ 456, 45 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.device_info
(self)
Return the device info for the iZone system.
Return the device info for the iZone system.
def device_info(self): """Return the device info for the iZone system.""" return self._device_info
[ "def", "device_info", "(", "self", ")", ":", "return", "self", ".", "_device_info" ]
[ 459, 4 ]
[ 461, 32 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.unique_id
(self)
Return the ID of the controller device.
Return the ID of the controller device.
def unique_id(self): """Return the ID of the controller device.""" return f"{self._controller.unique_id}_z{self._zone.index + 1}"
[ "def", "unique_id", "(", "self", ")", ":", "return", "f\"{self._controller.unique_id}_z{self._zone.index + 1}\"" ]
[ 464, 4 ]
[ 466, 70 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.name
(self)
Return the name of the entity.
Return the name of the entity.
def name(self) -> str: """Return the name of the entity.""" return self._name
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_name" ]
[ 469, 4 ]
[ 471, 25 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.should_poll
(self)
Return True if entity has to be polled for state. False if entity pushes its state to HA.
Return True if entity has to be polled for state.
def should_poll(self) -> bool: """Return True if entity has to be polled for state. False if entity pushes its state to HA. """ return False
[ "def", "should_poll", "(", "self", ")", "->", "bool", ":", "return", "False" ]
[ 474, 4 ]
[ 479, 20 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.supported_features
(self)
Return the list of supported features.
Return the list of supported features.
def supported_features(self): """Return the list of supported features.""" if self._zone.mode == Zone.Mode.AUTO: return self._supported_features return self._supported_features & ~SUPPORT_TARGET_TEMPERATURE
[ "def", "supported_features", "(", "self", ")", ":", "if", "self", ".", "_zone", ".", "mode", "==", "Zone", ".", "Mode", ".", "AUTO", ":", "return", "self", ".", "_supported_features", "return", "self", ".", "_supported_features", "&", "~", "SUPPORT_TARGET_TEMPERATURE" ]
[ 483, 4 ]
[ 487, 69 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.temperature_unit
(self)
Return the unit of measurement which this thermostat uses.
Return the unit of measurement which this thermostat uses.
def temperature_unit(self): """Return the unit of measurement which this thermostat uses.""" return TEMP_CELSIUS
[ "def", "temperature_unit", "(", "self", ")", ":", "return", "TEMP_CELSIUS" ]
[ 490, 4 ]
[ 492, 27 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.precision
(self)
Return the precision of the system.
Return the precision of the system.
def precision(self): """Return the precision of the system.""" return PRECISION_TENTHS
[ "def", "precision", "(", "self", ")", ":", "return", "PRECISION_TENTHS" ]
[ 495, 4 ]
[ 497, 31 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.hvac_mode
(self)
Return current operation ie. heat, cool, idle.
Return current operation ie. heat, cool, idle.
def hvac_mode(self): """Return current operation ie. heat, cool, idle.""" mode = self._zone.mode for (key, value) in self._state_to_pizone.items(): if value == mode: return key return None
[ "def", "hvac_mode", "(", "self", ")", ":", "mode", "=", "self", ".", "_zone", ".", "mode", "for", "(", "key", ",", "value", ")", "in", "self", ".", "_state_to_pizone", ".", "items", "(", ")", ":", "if", "value", "==", "mode", ":", "return", "key", "return", "None" ]
[ 500, 4 ]
[ 506, 19 ]
python
en
['nl', 'en', 'en']
True
ZoneDevice.hvac_modes
(self)
Return the list of available operation modes.
Return the list of available operation modes.
def hvac_modes(self): """Return the list of available operation modes.""" return list(self._state_to_pizone)
[ "def", "hvac_modes", "(", "self", ")", ":", "return", "list", "(", "self", ".", "_state_to_pizone", ")" ]
[ 509, 4 ]
[ 511, 42 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.current_temperature
(self)
Return the current temperature.
Return the current temperature.
def current_temperature(self): """Return the current temperature.""" return self._zone.temp_current
[ "def", "current_temperature", "(", "self", ")", ":", "return", "self", ".", "_zone", ".", "temp_current" ]
[ 514, 4 ]
[ 516, 38 ]
python
en
['en', 'la', 'en']
True
ZoneDevice.target_temperature
(self)
Return the temperature we try to reach.
Return the temperature we try to reach.
def target_temperature(self): """Return the temperature we try to reach.""" if self._zone.type != Zone.Type.AUTO: return None return self._zone.temp_setpoint
[ "def", "target_temperature", "(", "self", ")", ":", "if", "self", ".", "_zone", ".", "type", "!=", "Zone", ".", "Type", ".", "AUTO", ":", "return", "None", "return", "self", ".", "_zone", ".", "temp_setpoint" ]
[ 519, 4 ]
[ 523, 39 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.target_temperature_step
(self)
Return the supported step of target temperature.
Return the supported step of target temperature.
def target_temperature_step(self): """Return the supported step of target temperature.""" return 0.5
[ "def", "target_temperature_step", "(", "self", ")", ":", "return", "0.5" ]
[ 526, 4 ]
[ 528, 18 ]
python
en
['en', 'en', 'en']
True
ZoneDevice.min_temp
(self)
Return the minimum temperature.
Return the minimum temperature.
def min_temp(self): """Return the minimum temperature.""" return self._controller.min_temp
[ "def", "min_temp", "(", "self", ")", ":", "return", "self", ".", "_controller", ".", "min_temp" ]
[ 531, 4 ]
[ 533, 40 ]
python
en
['en', 'la', 'en']
True
ZoneDevice.max_temp
(self)
Return the maximum temperature.
Return the maximum temperature.
def max_temp(self): """Return the maximum temperature.""" return self._controller.max_temp
[ "def", "max_temp", "(", "self", ")", ":", "return", "self", ".", "_controller", ".", "max_temp" ]
[ 536, 4 ]
[ 538, 40 ]
python
en
['en', 'la', 'en']
True
ZoneDevice.async_set_temperature
(self, **kwargs)
Set new target temperature.
Set new target temperature.
async def async_set_temperature(self, **kwargs): """Set new target temperature.""" if self._zone.mode != Zone.Mode.AUTO: return temp = kwargs.get(ATTR_TEMPERATURE) if temp is not None: await self._controller.wrap_and_catch(self._zone.set_temp_setpoint(temp))
[ "async", "def", "async_set_temperature", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "_zone", ".", "mode", "!=", "Zone", ".", "Mode", ".", "AUTO", ":", "return", "temp", "=", "kwargs", ".", "get", "(", "ATTR_TEMPERATURE", ")", "if", "temp", "is", "not", "None", ":", "await", "self", ".", "_controller", ".", "wrap_and_catch", "(", "self", ".", "_zone", ".", "set_temp_setpoint", "(", "temp", ")", ")" ]
[ 540, 4 ]
[ 546, 85 ]
python
en
['en', 'ca', 'en']
True
ZoneDevice.async_set_hvac_mode
(self, hvac_mode: str)
Set new target operation mode.
Set new target operation mode.
async def async_set_hvac_mode(self, hvac_mode: str) -> None: """Set new target operation mode.""" mode = self._state_to_pizone[hvac_mode] await self._controller.wrap_and_catch(self._zone.set_mode(mode)) self.async_write_ha_state()
[ "async", "def", "async_set_hvac_mode", "(", "self", ",", "hvac_mode", ":", "str", ")", "->", "None", ":", "mode", "=", "self", ".", "_state_to_pizone", "[", "hvac_mode", "]", "await", "self", ".", "_controller", ".", "wrap_and_catch", "(", "self", ".", "_zone", ".", "set_mode", "(", "mode", ")", ")", "self", ".", "async_write_ha_state", "(", ")" ]
[ 548, 4 ]
[ 552, 35 ]
python
en
['nl', 'en', 'en']
True
ZoneDevice.is_on
(self)
Return true if on.
Return true if on.
def is_on(self): """Return true if on.""" return self._zone.mode != Zone.Mode.CLOSE
[ "def", "is_on", "(", "self", ")", ":", "return", "self", ".", "_zone", ".", "mode", "!=", "Zone", ".", "Mode", ".", "CLOSE" ]
[ 555, 4 ]
[ 557, 49 ]
python
en
['en', 'mt', 'en']
True
ZoneDevice.async_turn_on
(self)
Turn device on (open zone).
Turn device on (open zone).
async def async_turn_on(self): """Turn device on (open zone).""" if self._zone.type == Zone.Type.AUTO: await self._controller.wrap_and_catch(self._zone.set_mode(Zone.Mode.AUTO)) else: await self._controller.wrap_and_catch(self._zone.set_mode(Zone.Mode.OPEN)) self.async_write_ha_state()
[ "async", "def", "async_turn_on", "(", "self", ")", ":", "if", "self", ".", "_zone", ".", "type", "==", "Zone", ".", "Type", ".", "AUTO", ":", "await", "self", ".", "_controller", ".", "wrap_and_catch", "(", "self", ".", "_zone", ".", "set_mode", "(", "Zone", ".", "Mode", ".", "AUTO", ")", ")", "else", ":", "await", "self", ".", "_controller", ".", "wrap_and_catch", "(", "self", ".", "_zone", ".", "set_mode", "(", "Zone", ".", "Mode", ".", "OPEN", ")", ")", "self", ".", "async_write_ha_state", "(", ")" ]
[ 559, 4 ]
[ 565, 35 ]
python
en
['nl', 'en', 'en']
True
ZoneDevice.async_turn_off
(self)
Turn device off (close zone).
Turn device off (close zone).
async def async_turn_off(self): """Turn device off (close zone).""" await self._controller.wrap_and_catch(self._zone.set_mode(Zone.Mode.CLOSE)) self.async_write_ha_state()
[ "async", "def", "async_turn_off", "(", "self", ")", ":", "await", "self", ".", "_controller", ".", "wrap_and_catch", "(", "self", ".", "_zone", ".", "set_mode", "(", "Zone", ".", "Mode", ".", "CLOSE", ")", ")", "self", ".", "async_write_ha_state", "(", ")" ]
[ 567, 4 ]
[ 570, 35 ]
python
en
['nl', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the Tellstick sensors.
Set up the Tellstick sensors.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Tellstick sensors.""" sensor_value_descriptions = { tellcore_constants.TELLSTICK_TEMPERATURE: DatatypeDescription( "temperature", config.get(CONF_TEMPERATURE_SCALE) ), tellcore_constants.TELLSTICK_HUMIDITY: DatatypeDescription( "humidity", PERCENTAGE ), tellcore_constants.TELLSTICK_RAINRATE: DatatypeDescription("rain rate", ""), tellcore_constants.TELLSTICK_RAINTOTAL: DatatypeDescription("rain total", ""), tellcore_constants.TELLSTICK_WINDDIRECTION: DatatypeDescription( "wind direction", "" ), tellcore_constants.TELLSTICK_WINDAVERAGE: DatatypeDescription( "wind average", "" ), tellcore_constants.TELLSTICK_WINDGUST: DatatypeDescription("wind gust", ""), } try: tellcore_lib = telldus.TelldusCore() except OSError: _LOGGER.exception("Could not initialize Tellstick") return sensors = [] datatype_mask = config.get(CONF_DATATYPE_MASK) if config[CONF_ONLY_NAMED]: named_sensors = {} for named_sensor in config[CONF_ONLY_NAMED]: name = named_sensor[CONF_NAME] proto = named_sensor.get(CONF_PROTOCOL) model = named_sensor.get(CONF_MODEL) id_ = named_sensor[CONF_ID] if proto is not None: if model is not None: named_sensors[f"{proto}{model}{id_}"] = name else: named_sensors[f"{proto}{id_}"] = name else: named_sensors[id_] = name for tellcore_sensor in tellcore_lib.sensors(): if not config[CONF_ONLY_NAMED]: sensor_name = str(tellcore_sensor.id) else: proto_id = f"{tellcore_sensor.protocol}{tellcore_sensor.id}" proto_model_id = "{}{}{}".format( tellcore_sensor.protocol, tellcore_sensor.model, tellcore_sensor.id ) if tellcore_sensor.id in named_sensors: sensor_name = named_sensors[tellcore_sensor.id] elif proto_id in named_sensors: sensor_name = named_sensors[proto_id] elif proto_model_id in named_sensors: sensor_name = named_sensors[proto_model_id] else: continue for datatype in sensor_value_descriptions: if datatype & datatype_mask and tellcore_sensor.has_value(datatype): sensor_info = sensor_value_descriptions[datatype] sensors.append( TellstickSensor(sensor_name, tellcore_sensor, datatype, sensor_info) ) add_entities(sensors)
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "sensor_value_descriptions", "=", "{", "tellcore_constants", ".", "TELLSTICK_TEMPERATURE", ":", "DatatypeDescription", "(", "\"temperature\"", ",", "config", ".", "get", "(", "CONF_TEMPERATURE_SCALE", ")", ")", ",", "tellcore_constants", ".", "TELLSTICK_HUMIDITY", ":", "DatatypeDescription", "(", "\"humidity\"", ",", "PERCENTAGE", ")", ",", "tellcore_constants", ".", "TELLSTICK_RAINRATE", ":", "DatatypeDescription", "(", "\"rain rate\"", ",", "\"\"", ")", ",", "tellcore_constants", ".", "TELLSTICK_RAINTOTAL", ":", "DatatypeDescription", "(", "\"rain total\"", ",", "\"\"", ")", ",", "tellcore_constants", ".", "TELLSTICK_WINDDIRECTION", ":", "DatatypeDescription", "(", "\"wind direction\"", ",", "\"\"", ")", ",", "tellcore_constants", ".", "TELLSTICK_WINDAVERAGE", ":", "DatatypeDescription", "(", "\"wind average\"", ",", "\"\"", ")", ",", "tellcore_constants", ".", "TELLSTICK_WINDGUST", ":", "DatatypeDescription", "(", "\"wind gust\"", ",", "\"\"", ")", ",", "}", "try", ":", "tellcore_lib", "=", "telldus", ".", "TelldusCore", "(", ")", "except", "OSError", ":", "_LOGGER", ".", "exception", "(", "\"Could not initialize Tellstick\"", ")", "return", "sensors", "=", "[", "]", "datatype_mask", "=", "config", ".", "get", "(", "CONF_DATATYPE_MASK", ")", "if", "config", "[", "CONF_ONLY_NAMED", "]", ":", "named_sensors", "=", "{", "}", "for", "named_sensor", "in", "config", "[", "CONF_ONLY_NAMED", "]", ":", "name", "=", "named_sensor", "[", "CONF_NAME", "]", "proto", "=", "named_sensor", ".", "get", "(", "CONF_PROTOCOL", ")", "model", "=", "named_sensor", ".", "get", "(", "CONF_MODEL", ")", "id_", "=", "named_sensor", "[", "CONF_ID", "]", "if", "proto", "is", "not", "None", ":", "if", "model", "is", "not", "None", ":", "named_sensors", "[", "f\"{proto}{model}{id_}\"", "]", "=", "name", "else", ":", "named_sensors", "[", "f\"{proto}{id_}\"", "]", "=", "name", "else", ":", "named_sensors", "[", "id_", "]", "=", "name", "for", "tellcore_sensor", "in", "tellcore_lib", ".", "sensors", "(", ")", ":", "if", "not", "config", "[", "CONF_ONLY_NAMED", "]", ":", "sensor_name", "=", "str", "(", "tellcore_sensor", ".", "id", ")", "else", ":", "proto_id", "=", "f\"{tellcore_sensor.protocol}{tellcore_sensor.id}\"", "proto_model_id", "=", "\"{}{}{}\"", ".", "format", "(", "tellcore_sensor", ".", "protocol", ",", "tellcore_sensor", ".", "model", ",", "tellcore_sensor", ".", "id", ")", "if", "tellcore_sensor", ".", "id", "in", "named_sensors", ":", "sensor_name", "=", "named_sensors", "[", "tellcore_sensor", ".", "id", "]", "elif", "proto_id", "in", "named_sensors", ":", "sensor_name", "=", "named_sensors", "[", "proto_id", "]", "elif", "proto_model_id", "in", "named_sensors", ":", "sensor_name", "=", "named_sensors", "[", "proto_model_id", "]", "else", ":", "continue", "for", "datatype", "in", "sensor_value_descriptions", ":", "if", "datatype", "&", "datatype_mask", "and", "tellcore_sensor", ".", "has_value", "(", "datatype", ")", ":", "sensor_info", "=", "sensor_value_descriptions", "[", "datatype", "]", "sensors", ".", "append", "(", "TellstickSensor", "(", "sensor_name", ",", "tellcore_sensor", ",", "datatype", ",", "sensor_info", ")", ")", "add_entities", "(", "sensors", ")" ]
[ 56, 0 ]
[ 125, 25 ]
python
en
['en', 'sq', 'en']
True
TellstickSensor.__init__
(self, name, tellcore_sensor, datatype, sensor_info)
Initialize the sensor.
Initialize the sensor.
def __init__(self, name, tellcore_sensor, datatype, sensor_info): """Initialize the sensor.""" self._datatype = datatype self._tellcore_sensor = tellcore_sensor self._unit_of_measurement = sensor_info.unit or None self._value = None self._name = f"{name} {sensor_info.name}"
[ "def", "__init__", "(", "self", ",", "name", ",", "tellcore_sensor", ",", "datatype", ",", "sensor_info", ")", ":", "self", ".", "_datatype", "=", "datatype", "self", ".", "_tellcore_sensor", "=", "tellcore_sensor", "self", ".", "_unit_of_measurement", "=", "sensor_info", ".", "unit", "or", "None", "self", ".", "_value", "=", "None", "self", ".", "_name", "=", "f\"{name} {sensor_info.name}\"" ]
[ 131, 4 ]
[ 138, 49 ]
python
en
['en', 'en', 'en']
True
TellstickSensor.name
(self)
Return the name of the sensor.
Return the name of the sensor.
def name(self): """Return the name of the sensor.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 141, 4 ]
[ 143, 25 ]
python
en
['en', 'mi', 'en']
True
TellstickSensor.state
(self)
Return the state of the sensor.
Return the state of the sensor.
def state(self): """Return the state of the sensor.""" return self._value
[ "def", "state", "(", "self", ")", ":", "return", "self", ".", "_value" ]
[ 146, 4 ]
[ 148, 26 ]
python
en
['en', 'en', 'en']
True
TellstickSensor.unit_of_measurement
(self)
Return the unit of measurement of this entity, if any.
Return the unit of measurement of this entity, if any.
def unit_of_measurement(self): """Return the unit of measurement of this entity, if any.""" return self._unit_of_measurement
[ "def", "unit_of_measurement", "(", "self", ")", ":", "return", "self", ".", "_unit_of_measurement" ]
[ 151, 4 ]
[ 153, 40 ]
python
en
['en', 'en', 'en']
True
TellstickSensor.update
(self)
Update tellstick sensor.
Update tellstick sensor.
def update(self): """Update tellstick sensor.""" self._value = self._tellcore_sensor.value(self._datatype).value
[ "def", "update", "(", "self", ")", ":", "self", ".", "_value", "=", "self", ".", "_tellcore_sensor", ".", "value", "(", "self", ".", "_datatype", ")", ".", "value" ]
[ 155, 4 ]
[ 157, 71 ]
python
en
['en', 'lb', 'en']
True
async_setup
(hass: HomeAssistantType, config: ConfigType)
Set up the OVO Energy components.
Set up the OVO Energy components.
async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: """Set up the OVO Energy components.""" return True
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistantType", ",", "config", ":", "ConfigType", ")", "->", "bool", ":", "return", "True" ]
[ 24, 0 ]
[ 26, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass: HomeAssistantType, entry: ConfigEntry)
Set up OVO Energy from a config entry.
Set up OVO Energy from a config entry.
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool: """Set up OVO Energy from a config entry.""" client = OVOEnergy() try: await client.authenticate(entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD]) except aiohttp.ClientError as exception: _LOGGER.warning(exception) raise ConfigEntryNotReady from exception async def async_update_data() -> OVODailyUsage: """Fetch data from OVO Energy.""" now = datetime.utcnow() async with async_timeout.timeout(10): try: await client.authenticate( entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD] ) return await client.get_daily_usage(now.strftime("%Y-%m")) except aiohttp.ClientError as exception: _LOGGER.warning(exception) return None coordinator = DataUpdateCoordinator( hass, _LOGGER, # Name of the data. For logging purposes. name="sensor", update_method=async_update_data, # Polling interval. Will only be polled if there are subscribers. update_interval=timedelta(seconds=300), ) hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = { DATA_CLIENT: client, DATA_COORDINATOR: coordinator, } # Fetch initial data so we have data when entities subscribe await coordinator.async_refresh() # Setup components hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, "sensor") ) return True
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistantType", ",", "entry", ":", "ConfigEntry", ")", "->", "bool", ":", "client", "=", "OVOEnergy", "(", ")", "try", ":", "await", "client", ".", "authenticate", "(", "entry", ".", "data", "[", "CONF_USERNAME", "]", ",", "entry", ".", "data", "[", "CONF_PASSWORD", "]", ")", "except", "aiohttp", ".", "ClientError", "as", "exception", ":", "_LOGGER", ".", "warning", "(", "exception", ")", "raise", "ConfigEntryNotReady", "from", "exception", "async", "def", "async_update_data", "(", ")", "->", "OVODailyUsage", ":", "\"\"\"Fetch data from OVO Energy.\"\"\"", "now", "=", "datetime", ".", "utcnow", "(", ")", "async", "with", "async_timeout", ".", "timeout", "(", "10", ")", ":", "try", ":", "await", "client", ".", "authenticate", "(", "entry", ".", "data", "[", "CONF_USERNAME", "]", ",", "entry", ".", "data", "[", "CONF_PASSWORD", "]", ")", "return", "await", "client", ".", "get_daily_usage", "(", "now", ".", "strftime", "(", "\"%Y-%m\"", ")", ")", "except", "aiohttp", ".", "ClientError", "as", "exception", ":", "_LOGGER", ".", "warning", "(", "exception", ")", "return", "None", "coordinator", "=", "DataUpdateCoordinator", "(", "hass", ",", "_LOGGER", ",", "# Name of the data. For logging purposes.", "name", "=", "\"sensor\"", ",", "update_method", "=", "async_update_data", ",", "# Polling interval. Will only be polled if there are subscribers.", "update_interval", "=", "timedelta", "(", "seconds", "=", "300", ")", ",", ")", "hass", ".", "data", ".", "setdefault", "(", "DOMAIN", ",", "{", "}", ")", "hass", ".", "data", "[", "DOMAIN", "]", "[", "entry", ".", "entry_id", "]", "=", "{", "DATA_CLIENT", ":", "client", ",", "DATA_COORDINATOR", ":", "coordinator", ",", "}", "# Fetch initial data so we have data when entities subscribe", "await", "coordinator", ".", "async_refresh", "(", ")", "# Setup components", "hass", ".", "async_create_task", "(", "hass", ".", "config_entries", ".", "async_forward_entry_setup", "(", "entry", ",", "\"sensor\"", ")", ")", "return", "True" ]
[ 29, 0 ]
[ 77, 15 ]
python
en
['en', 'en', 'en']
True
async_unload_entry
(hass: HomeAssistantType, entry: ConfigType)
Unload OVO Energy config entry.
Unload OVO Energy config entry.
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigType) -> bool: """Unload OVO Energy config entry.""" # Unload sensors await hass.config_entries.async_forward_entry_unload(entry, "sensor") del hass.data[DOMAIN][entry.entry_id] return True
[ "async", "def", "async_unload_entry", "(", "hass", ":", "HomeAssistantType", ",", "entry", ":", "ConfigType", ")", "->", "bool", ":", "# Unload sensors", "await", "hass", ".", "config_entries", ".", "async_forward_entry_unload", "(", "entry", ",", "\"sensor\"", ")", "del", "hass", ".", "data", "[", "DOMAIN", "]", "[", "entry", ".", "entry_id", "]", "return", "True" ]
[ 80, 0 ]
[ 87, 15 ]
python
en
['hu', 'en', 'en']
True
OVOEnergyEntity.__init__
( self, coordinator: DataUpdateCoordinator, client: OVOEnergy, key: str, name: str, icon: str, )
Initialize the OVO Energy entity.
Initialize the OVO Energy entity.
def __init__( self, coordinator: DataUpdateCoordinator, client: OVOEnergy, key: str, name: str, icon: str, ) -> None: """Initialize the OVO Energy entity.""" super().__init__(coordinator) self._client = client self._key = key self._name = name self._icon = icon self._available = True
[ "def", "__init__", "(", "self", ",", "coordinator", ":", "DataUpdateCoordinator", ",", "client", ":", "OVOEnergy", ",", "key", ":", "str", ",", "name", ":", "str", ",", "icon", ":", "str", ",", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "coordinator", ")", "self", ".", "_client", "=", "client", "self", ".", "_key", "=", "key", "self", ".", "_name", "=", "name", "self", ".", "_icon", "=", "icon", "self", ".", "_available", "=", "True" ]
[ 93, 4 ]
[ 107, 30 ]
python
en
['en', 'en', 'en']
True
OVOEnergyEntity.unique_id
(self)
Return the unique ID for this sensor.
Return the unique ID for this sensor.
def unique_id(self) -> str: """Return the unique ID for this sensor.""" return self._key
[ "def", "unique_id", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_key" ]
[ 110, 4 ]
[ 112, 24 ]
python
en
['en', 'la', 'en']
True
OVOEnergyEntity.name
(self)
Return the name of the entity.
Return the name of the entity.
def name(self) -> str: """Return the name of the entity.""" return self._name
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_name" ]
[ 115, 4 ]
[ 117, 25 ]
python
en
['en', 'en', 'en']
True
OVOEnergyEntity.icon
(self)
Return the mdi icon of the entity.
Return the mdi icon of the entity.
def icon(self) -> str: """Return the mdi icon of the entity.""" return self._icon
[ "def", "icon", "(", "self", ")", "->", "str", ":", "return", "self", ".", "_icon" ]
[ 120, 4 ]
[ 122, 25 ]
python
en
['en', 'en', 'en']
True
OVOEnergyEntity.available
(self)
Return True if entity is available.
Return True if entity is available.
def available(self) -> bool: """Return True if entity is available.""" return self.coordinator.last_update_success and self._available
[ "def", "available", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "coordinator", ".", "last_update_success", "and", "self", ".", "_available" ]
[ 125, 4 ]
[ 127, 71 ]
python
en
['en', 'en', 'en']
True
OVOEnergyDeviceEntity.device_info
(self)
Return device information about this OVO Energy instance.
Return device information about this OVO Energy instance.
def device_info(self) -> Dict[str, Any]: """Return device information about this OVO Energy instance.""" return { "identifiers": {(DOMAIN, self._client.account_id)}, "manufacturer": "OVO Energy", "name": self._client.account_id, "entry_type": "service", }
[ "def", "device_info", "(", "self", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "return", "{", "\"identifiers\"", ":", "{", "(", "DOMAIN", ",", "self", ".", "_client", ".", "account_id", ")", "}", ",", "\"manufacturer\"", ":", "\"OVO Energy\"", ",", "\"name\"", ":", "self", ".", "_client", ".", "account_id", ",", "\"entry_type\"", ":", "\"service\"", ",", "}" ]
[ 134, 4 ]
[ 141, 9 ]
python
en
['en', 'en', 'en']
True
entities
(hass)
Initialize the test light.
Initialize the test light.
def entities(hass): """Initialize the test light.""" platform = getattr(hass.components, "test.light") platform.init() yield platform.ENTITIES[0:2]
[ "def", "entities", "(", "hass", ")", ":", "platform", "=", "getattr", "(", "hass", ".", "components", ",", "\"test.light\"", ")", "platform", ".", "init", "(", ")", "yield", "platform", ".", "ENTITIES", "[", "0", ":", "2", "]" ]
[ 14, 0 ]
[ 18, 32 ]
python
en
['en', 'en', 'en']
True
test_config_yaml_alias_anchor
(hass, entities)
Test the usage of YAML aliases and anchors. The following test scene configuration is equivalent to: scene: - name: test entities: light_1: &light_1_state state: 'on' brightness: 100 light_2: *light_1_state When encountering a YAML alias/anchor, the PyYAML parser will use a reference to the original dictionary, instead of creating a copy, so care needs to be taken to not modify the original.
Test the usage of YAML aliases and anchors.
async def test_config_yaml_alias_anchor(hass, entities): """Test the usage of YAML aliases and anchors. The following test scene configuration is equivalent to: scene: - name: test entities: light_1: &light_1_state state: 'on' brightness: 100 light_2: *light_1_state When encountering a YAML alias/anchor, the PyYAML parser will use a reference to the original dictionary, instead of creating a copy, so care needs to be taken to not modify the original. """ light_1, light_2 = await setup_lights(hass, entities) entity_state = {"state": "on", "brightness": 100} assert await async_setup_component( hass, scene.DOMAIN, { "scene": [ { "name": "test", "entities": { light_1.entity_id: entity_state, light_2.entity_id: entity_state, }, } ] }, ) await hass.async_block_till_done() await activate(hass, "scene.test") assert light.is_on(hass, light_1.entity_id) assert light.is_on(hass, light_2.entity_id) assert 100 == light_1.last_call("turn_on")[1].get("brightness") assert 100 == light_2.last_call("turn_on")[1].get("brightness")
[ "async", "def", "test_config_yaml_alias_anchor", "(", "hass", ",", "entities", ")", ":", "light_1", ",", "light_2", "=", "await", "setup_lights", "(", "hass", ",", "entities", ")", "entity_state", "=", "{", "\"state\"", ":", "\"on\"", ",", "\"brightness\"", ":", "100", "}", "assert", "await", "async_setup_component", "(", "hass", ",", "scene", ".", "DOMAIN", ",", "{", "\"scene\"", ":", "[", "{", "\"name\"", ":", "\"test\"", ",", "\"entities\"", ":", "{", "light_1", ".", "entity_id", ":", "entity_state", ",", "light_2", ".", "entity_id", ":", "entity_state", ",", "}", ",", "}", "]", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "activate", "(", "hass", ",", "\"scene.test\"", ")", "assert", "light", ".", "is_on", "(", "hass", ",", "light_1", ".", "entity_id", ")", "assert", "light", ".", "is_on", "(", "hass", ",", "light_2", ".", "entity_id", ")", "assert", "100", "==", "light_1", ".", "last_call", "(", "\"turn_on\"", ")", "[", "1", "]", ".", "get", "(", "\"brightness\"", ")", "assert", "100", "==", "light_2", ".", "last_call", "(", "\"turn_on\"", ")", "[", "1", "]", ".", "get", "(", "\"brightness\"", ")" ]
[ 21, 0 ]
[ 63, 67 ]
python
en
['en', 'en', 'en']
True
test_config_yaml_bool
(hass, entities)
Test parsing of booleans in yaml config.
Test parsing of booleans in yaml config.
async def test_config_yaml_bool(hass, entities): """Test parsing of booleans in yaml config.""" light_1, light_2 = await setup_lights(hass, entities) config = ( "scene:\n" " - name: test\n" " entities:\n" f" {light_1.entity_id}: on\n" f" {light_2.entity_id}:\n" " state: on\n" " brightness: 100\n" ) with io.StringIO(config) as file: doc = yaml_loader.yaml.safe_load(file) assert await async_setup_component(hass, scene.DOMAIN, doc) await hass.async_block_till_done() await activate(hass, "scene.test") assert light.is_on(hass, light_1.entity_id) assert light.is_on(hass, light_2.entity_id) assert 100 == light_2.last_call("turn_on")[1].get("brightness")
[ "async", "def", "test_config_yaml_bool", "(", "hass", ",", "entities", ")", ":", "light_1", ",", "light_2", "=", "await", "setup_lights", "(", "hass", ",", "entities", ")", "config", "=", "(", "\"scene:\\n\"", "\" - name: test\\n\"", "\" entities:\\n\"", "f\" {light_1.entity_id}: on\\n\"", "f\" {light_2.entity_id}:\\n\"", "\" state: on\\n\"", "\" brightness: 100\\n\"", ")", "with", "io", ".", "StringIO", "(", "config", ")", "as", "file", ":", "doc", "=", "yaml_loader", ".", "yaml", ".", "safe_load", "(", "file", ")", "assert", "await", "async_setup_component", "(", "hass", ",", "scene", ".", "DOMAIN", ",", "doc", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "activate", "(", "hass", ",", "\"scene.test\"", ")", "assert", "light", ".", "is_on", "(", "hass", ",", "light_1", ".", "entity_id", ")", "assert", "light", ".", "is_on", "(", "hass", ",", "light_2", ".", "entity_id", ")", "assert", "100", "==", "light_2", ".", "last_call", "(", "\"turn_on\"", ")", "[", "1", "]", ".", "get", "(", "\"brightness\"", ")" ]
[ 66, 0 ]
[ 90, 67 ]
python
en
['en', 'en', 'en']
True
test_activate_scene
(hass, entities)
Test active scene.
Test active scene.
async def test_activate_scene(hass, entities): """Test active scene.""" light_1, light_2 = await setup_lights(hass, entities) assert await async_setup_component( hass, scene.DOMAIN, { "scene": [ { "name": "test", "entities": { light_1.entity_id: "on", light_2.entity_id: {"state": "on", "brightness": 100}, }, } ] }, ) await hass.async_block_till_done() await activate(hass, "scene.test") assert light.is_on(hass, light_1.entity_id) assert light.is_on(hass, light_2.entity_id) assert light_2.last_call("turn_on")[1].get("brightness") == 100 calls = async_mock_service(hass, "light", "turn_on") await hass.services.async_call( scene.DOMAIN, "turn_on", {"transition": 42, "entity_id": "scene.test"} ) await hass.async_block_till_done() assert len(calls) == 1 assert calls[0].domain == "light" assert calls[0].service == "turn_on" assert calls[0].data.get("transition") == 42
[ "async", "def", "test_activate_scene", "(", "hass", ",", "entities", ")", ":", "light_1", ",", "light_2", "=", "await", "setup_lights", "(", "hass", ",", "entities", ")", "assert", "await", "async_setup_component", "(", "hass", ",", "scene", ".", "DOMAIN", ",", "{", "\"scene\"", ":", "[", "{", "\"name\"", ":", "\"test\"", ",", "\"entities\"", ":", "{", "light_1", ".", "entity_id", ":", "\"on\"", ",", "light_2", ".", "entity_id", ":", "{", "\"state\"", ":", "\"on\"", ",", "\"brightness\"", ":", "100", "}", ",", "}", ",", "}", "]", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "await", "activate", "(", "hass", ",", "\"scene.test\"", ")", "assert", "light", ".", "is_on", "(", "hass", ",", "light_1", ".", "entity_id", ")", "assert", "light", ".", "is_on", "(", "hass", ",", "light_2", ".", "entity_id", ")", "assert", "light_2", ".", "last_call", "(", "\"turn_on\"", ")", "[", "1", "]", ".", "get", "(", "\"brightness\"", ")", "==", "100", "calls", "=", "async_mock_service", "(", "hass", ",", "\"light\"", ",", "\"turn_on\"", ")", "await", "hass", ".", "services", ".", "async_call", "(", "scene", ".", "DOMAIN", ",", "\"turn_on\"", ",", "{", "\"transition\"", ":", "42", ",", "\"entity_id\"", ":", "\"scene.test\"", "}", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "calls", ")", "==", "1", "assert", "calls", "[", "0", "]", ".", "domain", "==", "\"light\"", "assert", "calls", "[", "0", "]", ".", "service", "==", "\"turn_on\"", "assert", "calls", "[", "0", "]", ".", "data", ".", "get", "(", "\"transition\"", ")", "==", "42" ]
[ 93, 0 ]
[ 129, 48 ]
python
en
['en', 'sr', 'en']
True
activate
(hass, entity_id=ENTITY_MATCH_ALL)
Activate a scene.
Activate a scene.
async def activate(hass, entity_id=ENTITY_MATCH_ALL): """Activate a scene.""" data = {} if entity_id: data[ATTR_ENTITY_ID] = entity_id await hass.services.async_call(scene.DOMAIN, SERVICE_TURN_ON, data, blocking=True)
[ "async", "def", "activate", "(", "hass", ",", "entity_id", "=", "ENTITY_MATCH_ALL", ")", ":", "data", "=", "{", "}", "if", "entity_id", ":", "data", "[", "ATTR_ENTITY_ID", "]", "=", "entity_id", "await", "hass", ".", "services", ".", "async_call", "(", "scene", ".", "DOMAIN", ",", "SERVICE_TURN_ON", ",", "data", ",", "blocking", "=", "True", ")" ]
[ 132, 0 ]
[ 139, 86 ]
python
en
['en', 'it', 'en']
True
test_services_registered
(hass)
Test we register services with empty config.
Test we register services with empty config.
async def test_services_registered(hass): """Test we register services with empty config.""" assert await async_setup_component(hass, "scene", {}) assert hass.services.has_service("scene", "reload") assert hass.services.has_service("scene", "turn_on") assert hass.services.has_service("scene", "apply")
[ "async", "def", "test_services_registered", "(", "hass", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "\"scene\"", ",", "{", "}", ")", "assert", "hass", ".", "services", ".", "has_service", "(", "\"scene\"", ",", "\"reload\"", ")", "assert", "hass", ".", "services", ".", "has_service", "(", "\"scene\"", ",", "\"turn_on\"", ")", "assert", "hass", ".", "services", ".", "has_service", "(", "\"scene\"", ",", "\"apply\"", ")" ]
[ 142, 0 ]
[ 147, 54 ]
python
en
['en', 'en', 'en']
True
setup_lights
(hass, entities)
Set up the light component.
Set up the light component.
async def setup_lights(hass, entities): """Set up the light component.""" assert await async_setup_component( hass, light.DOMAIN, {light.DOMAIN: {"platform": "test"}} ) await hass.async_block_till_done() light_1, light_2 = entities await hass.services.async_call( "light", "turn_off", {"entity_id": [light_1.entity_id, light_2.entity_id]}, blocking=True, ) await hass.async_block_till_done() assert not light.is_on(hass, light_1.entity_id) assert not light.is_on(hass, light_2.entity_id) return light_1, light_2
[ "async", "def", "setup_lights", "(", "hass", ",", "entities", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "light", ".", "DOMAIN", ",", "{", "light", ".", "DOMAIN", ":", "{", "\"platform\"", ":", "\"test\"", "}", "}", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "light_1", ",", "light_2", "=", "entities", "await", "hass", ".", "services", ".", "async_call", "(", "\"light\"", ",", "\"turn_off\"", ",", "{", "\"entity_id\"", ":", "[", "light_1", ".", "entity_id", ",", "light_2", ".", "entity_id", "]", "}", ",", "blocking", "=", "True", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "not", "light", ".", "is_on", "(", "hass", ",", "light_1", ".", "entity_id", ")", "assert", "not", "light", ".", "is_on", "(", "hass", ",", "light_2", ".", "entity_id", ")", "return", "light_1", ",", "light_2" ]
[ 150, 0 ]
[ 170, 27 ]
python
en
['en', 'en', 'en']
True