Find a better way to access zones etc, than using the dict key #66

Open
opened 2023-12-16 09:05:51 +00:00 by thomasjsn · 1 comment
thomasjsn commented 2023-12-16 09:05:51 +00:00 (Migrated from git.homelab.no)

Now the dict[str, Zone] has the key both as dictionary key and as value attribute.

Now the `dict[str, Zone]` has the key both as dictionary key and as value attribute.
thomasjsn commented 2024-11-19 13:35:24 +00:00 (Migrated from git.homelab.no)
class Input:
    inputs: list[str] = []

class Sensor:
    sensors: list[str] = []

class Zone(Input, Sensor):

    @staticmethod
    def list() -> list[str]:
        return Input.inputs + Sensor.sensors

    @staticmethod
    def dict() -> dict[str, str]:
        return {x:x for x in Input.inputs} | {x:x for x in Sensor.sensors}

Input.inputs = [
    "input1"
    ]

Sensor.sensors = [
    "sensor1"
    ]

print(Zone.inputs)
print(Zone.list())
print(Zone.dict())
```python class Input: inputs: list[str] = [] class Sensor: sensors: list[str] = [] class Zone(Input, Sensor): @staticmethod def list() -> list[str]: return Input.inputs + Sensor.sensors @staticmethod def dict() -> dict[str, str]: return {x:x for x in Input.inputs} | {x:x for x in Sensor.sensors} Input.inputs = [ "input1" ] Sensor.sensors = [ "sensor1" ] print(Zone.inputs) print(Zone.list()) print(Zone.dict()) ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thomas/rpi-alarm#66
No description provided.