Skip to content

Commit

Permalink
Identify virtual remote by device type (#140)
Browse files Browse the repository at this point in the history
* Add VALVE_STATE to climate

* Identify virtual remote by device type

* Fix Device Exporter / format output
  • Loading branch information
SukramJ authored Jan 7, 2022
1 parent e36f896 commit eaac26e
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 13 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 0.15.1 (2022-01-07)
- Identify virtual remote by device type
- Fix Device Exporter / format output

Version 0.15.0 (2022-01-07)
- Use actions instead of buttons for virtual remotes

Expand Down
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def example_run(self):
await asyncio.sleep(1)
await asyncio.sleep(5)

for i in range(1600):
for i in range(16):
_LOGGER.debug("Sleeping (%i)", i)
await asyncio.sleep(2)
# Stop the central_1 thread so Python can exit properly.
Expand Down
2 changes: 1 addition & 1 deletion example_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async def example_run(self):
await asyncio.sleep(1)
await asyncio.sleep(5)

for i in range(1600):
for i in range(16):
_LOGGER.debug("Sleeping (%i)", i)
await asyncio.sleep(2)
# Stop the central_1 thread so Python can exit properly.
Expand Down
13 changes: 9 additions & 4 deletions hahomematic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ async def get_paramsets(
relevant_paramsets: list[str] | None = None,
) -> dict[str, dict[str, Any]]:
"""Get paramsets for provided device description."""
if not device_description:
return {}
paramsets: dict[str, dict[str, Any]] = {}
address = device_description[ATTR_HM_ADDRESS]
paramsets[address] = {}
Expand Down Expand Up @@ -523,10 +525,13 @@ async def get_all_system_variables(self) -> dict[str, Any]:

def get_virtual_remote(self) -> HmDevice | None:
"""Get the virtual remote for the Client."""
for virtual_address in HM_VIRTUAL_REMOTES:
virtual_remote = self._central.hm_devices.get(virtual_address)
if virtual_remote and virtual_remote.interface_id == self.interface_id:
return virtual_remote
for device_type in HM_VIRTUAL_REMOTES:
for hm_device in self._central.hm_devices.values():
if (
hm_device.interface_id == self.interface_id
and hm_device.device_type == device_type
):
return hm_device
return None


Expand Down
12 changes: 9 additions & 3 deletions hahomematic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,15 @@

HM_ENTITY_UNIT_REPLACE: dict[str, str] = {'"': "", "100%": "%", "% rF": "%"}

HM_VIRTUAL_REMOTE_HM = "BidCoS-RF"
HM_VIRTUAL_REMOTE_HMIP = "HmIP-RCV-1"
HM_VIRTUAL_REMOTES = [HM_VIRTUAL_REMOTE_HM, HM_VIRTUAL_REMOTE_HMIP]
# virtual remotes device_types
HM_VIRTUAL_REMOTE_HM = "HM-RCV-50"
HM_VIRTUAL_REMOTE_HMW = "HMW-RCV-50"
HM_VIRTUAL_REMOTE_HMIP = "HmIP-RCV-50"
HM_VIRTUAL_REMOTES = [
HM_VIRTUAL_REMOTE_HM,
HM_VIRTUAL_REMOTE_HMW,
HM_VIRTUAL_REMOTE_HMIP,
]


class HmPlatform(Enum):
Expand Down
2 changes: 1 addition & 1 deletion hahomematic/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def create_entities(self) -> set[BaseEntity]:
parameter=parameter,
parameter_data=parameter_data,
)
if self._device_address.startswith(tuple(HM_VIRTUAL_REMOTES)):
if self.device_type in HM_VIRTUAL_REMOTES:
entity = self.create_action(
channel_address=channel_address,
parameter=parameter,
Expand Down
1 change: 1 addition & 0 deletions hahomematic/devices/entity_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def __str__(self) -> str:
1: {
FIELD_HUMIDITY: "ACTUAL_HUMIDITY",
FIELD_TEMPERATURE: "ACTUAL_TEMPERATURE",
FIELD_LEVEL: "VALVE_STATE",
}
},
},
Expand Down
4 changes: 3 additions & 1 deletion hahomematic/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ async def export_data(self) -> None:
# anonymize device_descriptions
anonymize_device_descriptions: list[Any] = []
for device_description in device_descriptions.values():
if device_description == {}:
continue
new_device_description = copy(device_description)
new_device_description[ATTR_HM_ADDRESS] = self._anonymize_address(
address=new_device_description[ATTR_HM_ADDRESS]
Expand Down Expand Up @@ -107,7 +109,7 @@ def _save() -> int:
mode="w",
encoding=DEFAULT_ENCODING,
) as fptr:
json.dump(data, fptr)
json.dump(data, fptr, indent=2)
return DATA_SAVE_SUCCESS

return await self._central.async_add_executor_job(_save)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def readme():
},
PACKAGE_NAME = "hahomematic"
HERE = os.path.abspath(os.path.dirname(__file__))
VERSION = "0.15.0"
VERSION = "0.15.1"

PACKAGES = find_packages(exclude=["tests", "tests.*", "dist", "build"])

Expand Down
2 changes: 1 addition & 1 deletion tests/test_central.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def test_central(central, loop) -> None:
assert central.clients["ccu-dev-hm"].model == "PyDevCCU"
assert central.get_client().model == "PyDevCCU"
assert len(central.hm_devices) == 294
assert len(central.hm_entities) == 2237
assert len(central.hm_entities) == 2537

data = {}
for device in central.hm_devices.values():
Expand Down

0 comments on commit eaac26e

Please sign in to comment.