From e62f04217391b9e45418998f515ab2c471abbd78 Mon Sep 17 00:00:00 2001 From: iloveicedgreentea <31193909+iloveicedgreentea@users.noreply.github.com> Date: Fri, 25 Feb 2022 22:05:30 -0500 Subject: [PATCH 1/2] testing --- .../jvc_projectors/manifest.json | 4 +- custom_components/jvc_projectors/remote.py | 102 ++++-------------- 2 files changed, 23 insertions(+), 83 deletions(-) diff --git a/custom_components/jvc_projectors/manifest.json b/custom_components/jvc_projectors/manifest.json index 0b28029..09aa516 100644 --- a/custom_components/jvc_projectors/manifest.json +++ b/custom_components/jvc_projectors/manifest.json @@ -4,7 +4,7 @@ "config_flow": false, "documentation": "https://www.home-assistant.io/integrations/jvc_projector", "requirements": [ - "jvc-projector-remote-improved>=1.2.6" + "jvc-projector-remote-improved==1.2.7" ], "ssdp": [], "zeroconf": [], @@ -14,5 +14,5 @@ "@iloveicedgreentea" ], "iot_class": "local_polling", - "version": "1.2.5" + "version": "1.2.7" } \ No newline at end of file diff --git a/custom_components/jvc_projectors/remote.py b/custom_components/jvc_projectors/remote.py index 1bd0a4b..dda5fa2 100644 --- a/custom_components/jvc_projectors/remote.py +++ b/custom_components/jvc_projectors/remote.py @@ -37,11 +37,10 @@ ) -async def async_setup_platform( +async def async_setup_entry( hass: HomeAssistant, config: ConfigType, - async_add_entities: AddEntitiesCallback, - discovery_info: DiscoveryInfoType = None, + async_add_entities: AddEntitiesCallback ) -> None: """ Set up platform. @@ -49,10 +48,7 @@ async def async_setup_platform( host = config.get(CONF_HOST) name = config.get(CONF_NAME) password = config.get(CONF_PASSWORD) - # Maybe make this user supplied in the future - # timeout = config.get(CONF_TIMEOUT) - # IF this is not high enough connections will start tripping over each other - SCAN_INTERVAL = config.get(CONF_SCAN_INTERVAL) + async_add_entities( [ JVCRemote(name, host, password), @@ -106,6 +102,8 @@ def __init__( @property def should_poll(self): + # Polling is disabled as it is unreliable and will lock up commands at the moment + # Requires adding stronger locking and command buffering return False @property @@ -141,73 +139,26 @@ def is_on(self): async def async_turn_on(self, **kwargs): """Send the power on command.""" - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to run command") - # await asyncio.sleep(3) - async with self._lock: - _, success = await self.jvc_client.async_power_on() - if success: - self._state = True + await self.jvc_client.async_power_on() + self._state = True async def async_turn_off(self, **kwargs): """Send the power off command.""" - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to run command") - # await asyncio.sleep(3) - async with self._lock: - _, success = await self.jvc_client.async_power_off() - if success: - self._state = False - - async def _async_collect_updates(self): - """ - Run each update sequentially. Attributes to update should be added here - """ - # Okay clearly not enough locking - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to get power state") - # await asyncio.sleep(3) - - async with self._lock: - # Try to make it so if something is hanging, just end the connection - # otherwise it can just lock up the entire integration - try: - async with timeout(5): - self._state = await self.jvc_client.async_is_on() - except asyncio.TimeoutError: - _LOGGER.error("Timed out getting power state") - return - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to get low latency state") - # await asyncio.sleep(3) - - async with self._lock: - try: - async with timeout(5): - self._ll_state = await self.jvc_client.async_get_low_latency_state() - except asyncio.TimeoutError: - _LOGGER.error("Timed out getting low latency state") - return + await self.jvc_client.async_power_off() + self._state = False async def async_update(self): """Retrieve latest state.""" - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to run update") - # await asyncio.sleep(3) - - # await self._async_collect_updates() - self._state = await self.jvc_client.async_is_on() + # Not implemented yet + pass + # self._state = await self.jvc_client.async_is_on() # self._ll_state = await self.jvc_client.async_get_low_latency_state() async def async_send_command(self, command: list[str], **kwargs): """Send commands to a device.""" - # Wait until unlocked so commmands dont cause a failure loop - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to run command") - # await asyncio.sleep(3) async with self._lock: _, success = await self.jvc_client.async_exec_command(command) @@ -216,53 +167,42 @@ async def service_async_info(self) -> None: """ Brings up the info screen """ - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to run command") - # await asyncio.sleep(3) async with self._lock: - return await self.jvc_client.async_info() + await self.jvc_client.async_info() async def service_async_gaming_mode_hdr(self) -> None: """ Sets optimal gaming modes """ - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to run command") - # await asyncio.sleep(3) async with self._lock: - return await self.jvc_client.async_gaming_mode_hdr() + await self.jvc_client.async_gaming_mode_hdr() + self._ll_state = True async def service_async_gaming_mode_sdr(self) -> None: """ Sets optimal gaming modes """ - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to run command") - # await asyncio.sleep(3) async with self._lock: - return await self.jvc_client.async_gaming_mode_sdr() + await self.jvc_client.async_gaming_mode_sdr() + self._ll_state = True async def service_async_hdr_picture_mode(self) -> None: """ Sets optimal HDR modes """ - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to run command") - # await asyncio.sleep(3) async with self._lock: - return await self.jvc_client.async_hdr_picture_mode() + await self.jvc_client.async_hdr_picture_mode() + self._ll_state = False async def service_async_sdr_picture_mode(self) -> None: """ Sets optimal SDR modes """ - # if self._lock.locked(): - # _LOGGER.debug("State is locked. Waiting to run command") - # await asyncio.sleep(3) async with self._lock: - return await self.jvc_client.async_sdr_picture_mode() + await self.jvc_client.async_sdr_picture_mode() + self._ll_state = False From ca244c3b13087f6e2f1cf007985c8b857fd9fa7d Mon Sep 17 00:00:00 2001 From: iloveicedgreentea <31193909+iloveicedgreentea@users.noreply.github.com> Date: Fri, 25 Feb 2022 22:15:44 -0500 Subject: [PATCH 2/2] fix issues --- custom_components/jvc_projectors/remote.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/custom_components/jvc_projectors/remote.py b/custom_components/jvc_projectors/remote.py index dda5fa2..77dec7b 100644 --- a/custom_components/jvc_projectors/remote.py +++ b/custom_components/jvc_projectors/remote.py @@ -37,10 +37,11 @@ ) -async def async_setup_entry( +async def async_setup_platform( hass: HomeAssistant, config: ConfigType, - async_add_entities: AddEntitiesCallback + async_add_entities: AddEntitiesCallback, + discovery_info: DiscoveryInfoType = None, ) -> None: """ Set up platform.