mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
commit
6c138e2982
@ -23,14 +23,12 @@ from homeassistant.const import (
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import ATTRIBUTION, DOMAIN
|
||||
from .const import ATTRIBUTION, DOMAIN, DEFAULT_CACHEDB
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_POLLING = "polling"
|
||||
|
||||
DEFAULT_CACHEDB = "./abodepy_cache.pickle"
|
||||
|
||||
SERVICE_SETTINGS = "change_setting"
|
||||
SERVICE_CAPTURE_IMAGE = "capture_image"
|
||||
SERVICE_TRIGGER = "trigger_quick_action"
|
||||
|
@ -10,7 +10,7 @@ from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import callback
|
||||
|
||||
from .const import DOMAIN # pylint: disable=W0611
|
||||
from .const import DOMAIN, DEFAULT_CACHEDB # pylint: disable=W0611
|
||||
|
||||
CONF_POLLING = "polling"
|
||||
|
||||
@ -42,9 +42,12 @@ class AbodeFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
username = user_input[CONF_USERNAME]
|
||||
password = user_input[CONF_PASSWORD]
|
||||
polling = user_input.get(CONF_POLLING, False)
|
||||
cache = self.hass.config.path(DEFAULT_CACHEDB)
|
||||
|
||||
try:
|
||||
await self.hass.async_add_executor_job(Abode, username, password, True)
|
||||
await self.hass.async_add_executor_job(
|
||||
Abode, username, password, True, True, True, cache
|
||||
)
|
||||
|
||||
except (AbodeException, ConnectTimeout, HTTPError) as ex:
|
||||
_LOGGER.error("Unable to connect to Abode: %s", str(ex))
|
||||
|
@ -1,3 +1,5 @@
|
||||
"""Constants for the Abode Security System component."""
|
||||
DOMAIN = "abode"
|
||||
ATTRIBUTION = "Data provided by goabode.com"
|
||||
|
||||
DEFAULT_CACHEDB = "abodepy_cache.pickle"
|
||||
|
@ -180,13 +180,9 @@ class KNXLight(Light):
|
||||
@property
|
||||
def brightness(self):
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
if self.device.supports_brightness:
|
||||
return self.device.current_brightness
|
||||
if (
|
||||
self.device.supports_color or self.device.supports_rgbw
|
||||
) and self.device.current_color:
|
||||
return max(self.device.current_color)
|
||||
return None
|
||||
if not self.device.supports_brightness:
|
||||
return None
|
||||
return self.device.current_brightness
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
|
@ -6,7 +6,7 @@ from xml.etree.ElementTree import ParseError
|
||||
import plexapi.exceptions
|
||||
import requests.exceptions
|
||||
|
||||
from homeassistant.components.media_player import MediaPlayerDevice
|
||||
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN, MediaPlayerDevice
|
||||
from homeassistant.components.media_player.const import (
|
||||
MEDIA_TYPE_MOVIE,
|
||||
MEDIA_TYPE_MUSIC,
|
||||
@ -30,6 +30,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_registry import async_get_registry
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import (
|
||||
@ -56,10 +57,11 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up Plex media_player from a config entry."""
|
||||
server_id = config_entry.data[CONF_SERVER_IDENTIFIER]
|
||||
registry = await async_get_registry(hass)
|
||||
|
||||
def async_new_media_players(new_entities):
|
||||
_async_add_entities(
|
||||
hass, config_entry, async_add_entities, server_id, new_entities
|
||||
hass, registry, config_entry, async_add_entities, server_id, new_entities
|
||||
)
|
||||
|
||||
unsub = async_dispatcher_connect(
|
||||
@ -70,7 +72,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
|
||||
@callback
|
||||
def _async_add_entities(
|
||||
hass, config_entry, async_add_entities, server_id, new_entities
|
||||
hass, registry, config_entry, async_add_entities, server_id, new_entities
|
||||
):
|
||||
"""Set up Plex media_player entities."""
|
||||
entities = []
|
||||
@ -79,6 +81,19 @@ def _async_add_entities(
|
||||
plex_mp = PlexMediaPlayer(plexserver, **entity_params)
|
||||
entities.append(plex_mp)
|
||||
|
||||
# Migration to per-server unique_ids
|
||||
old_entity_id = registry.async_get_entity_id(
|
||||
MP_DOMAIN, PLEX_DOMAIN, plex_mp.machine_identifier
|
||||
)
|
||||
if old_entity_id is not None:
|
||||
new_unique_id = f"{server_id}:{plex_mp.machine_identifier}"
|
||||
_LOGGER.debug(
|
||||
"Migrating unique_id from [%s] to [%s]",
|
||||
plex_mp.machine_identifier,
|
||||
new_unique_id,
|
||||
)
|
||||
registry.async_update_entity(old_entity_id, new_unique_id=new_unique_id)
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
@ -126,6 +141,7 @@ class PlexMediaPlayer(MediaPlayerDevice):
|
||||
async def async_added_to_hass(self):
|
||||
"""Run when about to be added to hass."""
|
||||
server_id = self.plex_server.machine_identifier
|
||||
|
||||
unsub = async_dispatcher_connect(
|
||||
self.hass,
|
||||
PLEX_UPDATE_MEDIA_PLAYER_SIGNAL.format(self.unique_id),
|
||||
@ -315,6 +331,11 @@ class PlexMediaPlayer(MediaPlayerDevice):
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the id of this plex client."""
|
||||
return f"{self.plex_server.machine_identifier}:{self._machine_identifier}"
|
||||
|
||||
@property
|
||||
def machine_identifier(self):
|
||||
"""Return the Plex-provided identifier of this plex client."""
|
||||
return self._machine_identifier
|
||||
|
||||
@property
|
||||
|
@ -94,9 +94,10 @@ class PlexServer:
|
||||
|
||||
def refresh_entity(self, machine_identifier, device, session):
|
||||
"""Forward refresh dispatch to media_player."""
|
||||
unique_id = f"{self.machine_identifier}:{machine_identifier}"
|
||||
dispatcher_send(
|
||||
self._hass,
|
||||
PLEX_UPDATE_MEDIA_PLAYER_SIGNAL.format(machine_identifier),
|
||||
PLEX_UPDATE_MEDIA_PLAYER_SIGNAL.format(unique_id),
|
||||
device,
|
||||
session,
|
||||
)
|
||||
|
@ -1,6 +1,8 @@
|
||||
"""Support for SNMP enabled switch."""
|
||||
import logging
|
||||
|
||||
from pyasn1.type.univ import Integer
|
||||
|
||||
import pysnmp.hlapi.asyncio as hlapi
|
||||
from pysnmp.hlapi.asyncio import (
|
||||
CommunityData,
|
||||
@ -190,15 +192,20 @@ class SnmpSwitch(SwitchDevice):
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn on the switch."""
|
||||
await self._set(self._command_payload_on)
|
||||
if self._command_payload_on.isdigit():
|
||||
await self._set(Integer(self._command_payload_on))
|
||||
else:
|
||||
await self._set(self._command_payload_on)
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn off the switch."""
|
||||
await self._set(self._command_payload_off)
|
||||
if self._command_payload_on.isdigit():
|
||||
await self._set(Integer(self._command_payload_off))
|
||||
else:
|
||||
await self._set(self._command_payload_off)
|
||||
|
||||
async def async_update(self):
|
||||
"""Update the state."""
|
||||
|
||||
errindication, errstatus, errindex, restable = await getCmd(
|
||||
*self._request_args, ObjectType(ObjectIdentity(self._baseoid))
|
||||
)
|
||||
@ -215,8 +222,12 @@ class SnmpSwitch(SwitchDevice):
|
||||
for resrow in restable:
|
||||
if resrow[-1] == self._payload_on:
|
||||
self._state = True
|
||||
elif resrow[-1] == Integer(self._payload_on):
|
||||
self._state = True
|
||||
elif resrow[-1] == self._payload_off:
|
||||
self._state = False
|
||||
elif resrow[-1] == Integer(self._payload_off):
|
||||
self._state = False
|
||||
else:
|
||||
self._state = None
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Constants used by Home Assistant components."""
|
||||
MAJOR_VERSION = 0
|
||||
MINOR_VERSION = 101
|
||||
PATCH_VERSION = "1"
|
||||
PATCH_VERSION = "2"
|
||||
__short_version__ = "{}.{}".format(MAJOR_VERSION, MINOR_VERSION)
|
||||
__version__ = "{}.{}".format(__short_version__, PATCH_VERSION)
|
||||
REQUIRED_PYTHON_VER = (3, 6, 1)
|
||||
|
@ -48,8 +48,12 @@ async def async_get_integration_with_requirements(
|
||||
hass, integration.domain, integration.requirements
|
||||
)
|
||||
|
||||
for dependency in integration.dependencies:
|
||||
await async_get_integration_with_requirements(hass, dependency)
|
||||
deps = integration.dependencies + (integration.after_dependencies or [])
|
||||
|
||||
if deps:
|
||||
await asyncio.gather(
|
||||
*[async_get_integration_with_requirements(hass, dep) for dep in deps]
|
||||
)
|
||||
|
||||
return integration
|
||||
|
||||
|
@ -115,12 +115,19 @@ async def test_get_integration_with_requirements(hass):
|
||||
mock_integration(
|
||||
hass, MockModule("test_component_dep", requirements=["test-comp-dep==1.0.0"])
|
||||
)
|
||||
mock_integration(
|
||||
hass,
|
||||
MockModule(
|
||||
"test_component_after_dep", requirements=["test-comp-after-dep==1.0.0"]
|
||||
),
|
||||
)
|
||||
mock_integration(
|
||||
hass,
|
||||
MockModule(
|
||||
"test_component",
|
||||
requirements=["test-comp==1.0.0"],
|
||||
dependencies=["test_component_dep"],
|
||||
partial_manifest={"after_dependencies": ["test_component_after_dep"]},
|
||||
),
|
||||
)
|
||||
|
||||
@ -136,13 +143,15 @@ async def test_get_integration_with_requirements(hass):
|
||||
assert integration
|
||||
assert integration.domain == "test_component"
|
||||
|
||||
assert len(mock_is_installed.mock_calls) == 2
|
||||
assert len(mock_is_installed.mock_calls) == 3
|
||||
assert mock_is_installed.mock_calls[0][1][0] == "test-comp==1.0.0"
|
||||
assert mock_is_installed.mock_calls[1][1][0] == "test-comp-dep==1.0.0"
|
||||
assert mock_is_installed.mock_calls[2][1][0] == "test-comp-after-dep==1.0.0"
|
||||
|
||||
assert len(mock_inst.mock_calls) == 2
|
||||
assert len(mock_inst.mock_calls) == 3
|
||||
assert mock_inst.mock_calls[0][1][0] == "test-comp==1.0.0"
|
||||
assert mock_inst.mock_calls[1][1][0] == "test-comp-dep==1.0.0"
|
||||
assert mock_inst.mock_calls[2][1][0] == "test-comp-after-dep==1.0.0"
|
||||
|
||||
|
||||
async def test_install_with_wheels_index(hass):
|
||||
|
Loading…
x
Reference in New Issue
Block a user