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

Commit

Permalink
fix attr when off
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveicedgreentea committed Feb 17, 2024
1 parent f0c0a76 commit 932a928
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 79 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.PHONY: test dev_install build upload

dev_install:
python3 -m venv .venv
. .venv/bin/activate && \
pip3 install --upgrade pyjvc
test:
LOG_LEVEL=debug python -m unittest discover -s tests
160 changes: 81 additions & 79 deletions custom_components/jvc_projectors/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ def extra_state_attributes(self):
if self._state:
return asdict(self.jvc_client.attributes)

return {"power_state": self._state}
return {
"power_state": self._state,
"model": self.jvc_client.model_family,
}

@property
def is_on(self):
Expand Down Expand Up @@ -326,93 +329,92 @@ async def async_update(self):
and self.jvc_client.connection_open is True
):
# common stuff
attribute_getters = [
(self.jvc_client.is_on, "power_state"),
(self.jvc_client.get_source_status, "signal_status"),
(self.jvc_client.get_picture_mode, "picture_mode"),
(self.jvc_client.get_lamp_time, "lamp_time"),
(self.jvc_client.get_software_version, "software_version"),
]
# get power, signal and picture state
for getter, name in attribute_getters:
await self.attribute_queue.put((getter, name))

# wait for queue to empty
await self.attribute_queue.join()

# determine how to proceed based on above

if self.jvc_client.attributes.signal_status == "signal":
attribute_getters = []
_LOGGER.debug("updating state")
self._state = await self.jvc_client.is_on()
if self._state:
_LOGGER.debug("getting attributes")
attribute_getters.extend(
[
(self.jvc_client.get_content_type, "content_type"),
(self.jvc_client.get_content_type_trans, "content_type_trans"),
(self.jvc_client.get_input_mode, "input_mode"),
]
(self.jvc_client.get_source_status, "signal_status"),
(self.jvc_client.get_picture_mode, "picture_mode"),
(self.jvc_client.get_lamp_time, "lamp_time"),
(self.jvc_client.get_software_version, "software_version"),
)
if not "Unsupported" in self.jvc_client.model_family:
attribute_getters.extend(
[
(self.jvc_client.get_install_mode, "installation_mode"),
(self.jvc_client.get_aspect_ratio, "aspect_ratio"),
(self.jvc_client.get_color_mode, "color_mode"),
(self.jvc_client.get_input_level, "input_level"),
(self.jvc_client.get_mask_mode, "mask_mode"),
]
)
if any(x in self.jvc_client.model_family for x in ["NX9", "NZ"]):
attribute_getters.append(
(self.jvc_client.get_eshift_mode, "eshift"),
)
if "NZ" in self.jvc_client.model_family:
attribute_getters.extend(
[
(self.jvc_client.get_laser_power, "laser_power"),
(self.jvc_client.get_laser_mode, "laser_mode"),
(self.jvc_client.is_ll_on, "low_latency"),
]
)
else:
attribute_getters.append(
(self.jvc_client.get_lamp_power, "lamp_power"),
)

for getter, name in attribute_getters:
await self.attribute_queue.put((getter, name))

# get hdr attributes
await self.attribute_queue.join()

# HDR stuff
if any(
x in self.jvc_client.attributes.content_type_trans
for x in ["hdr", "hlg"]
):
# determine how to proceed based on above

if self.jvc_client.attributes.signal_status == "signal":
attribute_getters.extend(
[
(self.jvc_client.get_content_type, "content_type"),
(
self.jvc_client.get_content_type_trans,
"content_type_trans",
),
(self.jvc_client.get_input_mode, "input_mode"),
]
)
if not "Unsupported" in self.jvc_client.model_family:
attribute_getters.extend(
[
(self.jvc_client.get_install_mode, "installation_mode"),
(self.jvc_client.get_aspect_ratio, "aspect_ratio"),
(self.jvc_client.get_color_mode, "color_mode"),
(self.jvc_client.get_input_level, "input_level"),
(self.jvc_client.get_mask_mode, "mask_mode"),
]
)
if any(x in self.jvc_client.model_family for x in ["NX9", "NZ"]):
attribute_getters.append(
(self.jvc_client.get_eshift_mode, "eshift"),
)
if "NZ" in self.jvc_client.model_family:
attribute_getters.extend(
[
(self.jvc_client.get_laser_power, "laser_power"),
(self.jvc_client.get_laser_mode, "laser_mode"),
(self.jvc_client.is_ll_on, "low_latency"),
]
)
else:
attribute_getters.append(
(
self.jvc_client.get_theater_optimizer_state,
"theater_optimizer",
),
(self.jvc_client.get_lamp_power, "lamp_power"),
)
attribute_getters.extend(
[
(self.jvc_client.get_hdr_processing, "hdr_processing"),
(self.jvc_client.get_hdr_level, "hdr_level"),
(self.jvc_client.get_hdr_data, "hdr_data"),
]
)

# get all the updates
for getter, name in attribute_getters:
await self.attribute_queue.put((getter, name))
for getter, name in attribute_getters:
await self.attribute_queue.put((getter, name))

# get hdr attributes
await self.attribute_queue.join()

# HDR stuff
if any(
x in self.jvc_client.attributes.content_type_trans
for x in ["hdr", "hlg"]
):
if "NZ" in self.jvc_client.model_family:
attribute_getters.append(
(
self.jvc_client.get_theater_optimizer_state,
"theater_optimizer",
),
)
attribute_getters.extend(
[
(self.jvc_client.get_hdr_processing, "hdr_processing"),
(self.jvc_client.get_hdr_level, "hdr_level"),
(self.jvc_client.get_hdr_data, "hdr_data"),
]
)

await self.attribute_queue.join()
# get all the updates
for getter, name in attribute_getters:
await self.attribute_queue.put((getter, name))

# set the model
await self.attribute_queue.join()
else:
_LOGGER.debug("PJ is off")
# set the model
self.jvc_client.attributes.model = self.jvc_client.model_family
# just in case
self._state = self.jvc_client.attributes.power_state

async def async_send_command(self, command: Iterable[str], **kwargs):
"""Send commands to a device."""
Expand Down

0 comments on commit 932a928

Please sign in to comment.