Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from iloveicedgreentea/develop
Browse files Browse the repository at this point in the history
Update state and simplifiy
  • Loading branch information
iloveicedgreentea authored Feb 26, 2022
2 parents c054be2 + ca244c3 commit de6b08a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 80 deletions.
4 changes: 2 additions & 2 deletions custom_components/jvc_projectors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand All @@ -14,5 +14,5 @@
"@iloveicedgreentea"
],
"iot_class": "local_polling",
"version": "1.2.5"
"version": "1.2.7"
}
97 changes: 19 additions & 78 deletions custom_components/jvc_projectors/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,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),
Expand Down Expand Up @@ -106,6 +103,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
Expand Down Expand Up @@ -141,73 +140,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)
Expand All @@ -216,53 +168,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

0 comments on commit de6b08a

Please sign in to comment.