Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions examples/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ def print_attributes(title: str, attributes: dict[str, str]) -> None:
print(f"{label}: {value}")


def format_yes_no(*, value: bool) -> str:
"""Format a boolean as a readable yes/no value."""
return "yes" if value else "no"


def format_optional(value: Any) -> str:
"""Format optional device metadata for display."""
return "N/A" if value is None else str(value)


def get_hvac_action_name(status_code: int) -> str:
"""Map BSB-LAN parameter 8000 status code to a human-readable HVAC action.

Expand Down Expand Up @@ -180,6 +190,11 @@ async def print_device_info(device: Device, info: Info) -> None:
"Device Name": device.name or "N/A",
"Version": device.version or "N/A",
"Device Identification": device_identification,
"Bus Type": format_optional(device.bus),
"Bus Writable Flag": format_optional(device.buswritable),
"Bus Address": format_optional(device.busaddr),
"Bus Destination": format_optional(device.busdest),
"Supports Time Sync": format_yes_no(value=device.supports_time_sync),
}
print_attributes("Device Information", attributes)

Expand Down Expand Up @@ -319,6 +334,11 @@ async def main() -> None:

# Initialize BSBLAN with the configuration object
async with BSBLAN(config) as bsblan:
# Get and print device and general info, including bus metadata
device: Device = bsblan.device_info or await bsblan.device()
info: Info = await bsblan.info()
await print_device_info(device, info)

# Get and print state
state: State = await bsblan.state()
await print_state(state)
Expand All @@ -335,14 +355,12 @@ async def main() -> None:
sensor: Sensor = await bsblan.sensor()
await print_sensor(sensor)

# Get and print device and general info
device: Device = await bsblan.device()
info: Info = await bsblan.info()
await print_device_info(device, info)

# Get and print device time
device_time: DeviceTime = await bsblan.time()
await print_device_time(device_time)
if bsblan.supports_time_sync:
device_time: DeviceTime = await bsblan.time()
await print_device_time(device_time)
else:
print("\nDevice time is not available for this bus type")

# Get and print static state
static_state: StaticState = await bsblan.static_values()
Expand Down Expand Up @@ -375,13 +393,15 @@ async def main() -> None:
await bsblan.set_hot_water(SetHotWaterParam(dhw_time_programs=dhw_programs))

# Example: Set device time
print("\nSetting device time to current system time")
# Get current local system time and format it for BSB-LAN (DD.MM.YYYY HH:MM:SS)
# Note: Using local time intentionally for this demo to sync BSB-LAN
current_time = datetime.now().replace(microsecond=0) # noqa: DTZ005 - Demo uses local time
formatted_time = current_time.strftime("%d.%m.%Y %H:%M:%S")
print(f"Current system time: {formatted_time}")
await bsblan.set_time(formatted_time)
if bsblan.supports_time_sync:
print("\nSetting device time to current system time")
# Get current local system time and format it for BSB-LAN.
current_time = datetime.now().replace(microsecond=0) # noqa: DTZ005
formatted_time = current_time.strftime("%d.%m.%Y %H:%M:%S")
print(f"Current system time: {formatted_time}")
await bsblan.set_time(formatted_time)
else:
print("\nSkipping device time sync for this bus type")


if __name__ == "__main__":
Expand Down
Loading
Loading