How georgesak/home-assistant-crestron-component works
Main Components
• Crestron Custom Component: This is the core integration placed under the folder custom_components/crestron.
• Platform Modules: Inside the integration, several individual Python files implement Home Assistant platforms:
– binary_sensor.py
– climate.py
– cover.py
– media_player.py
– sensor.py
– switch.py
– light.py
• Core Integration Logic: Files like crestron.py, const.py, and manifest.json form the backbone of the integration (defining constants, domain, and Home Assistant metadata).
Relationships and Interactions
• Home Assistant’s Automation and Service Calls → These lead to the Crestron component functions (for instance, a call-service action like crestron.set_analog in an automation).
• The individual platform modules (e.g., climate.py or media_player.py) operate as drivers that register with Home Assistant using the metadata from manifest.json.
• The core module (crestron.py) coordinates communication with the Crestron control hardware, processing configuration and join commands.
• Configuration Flow: A user editing configuration.yaml and setting parameters (like port numbers and domains) will affect which instance of the custom component is activated.
Architectural Patterns and Design Principles
• Modularity: Each functionality (lights, sensors, climate, covers, etc.) is encapsulated in its own file.
• Separation of Concerns: The integration splits the “core” communication logic (crestron.py, const.py) from the “platform” specific implementations.
• Extensibility: The approach in README for running multiple instances (by copying and modifying manifest.json and const.py) indicates a pattern where the component can be duplicated and customized easily.
• Messaging/Command Pattern: The use of service calls (like crestron.set_analog) to send specific commands exemplifies a command-driven design.