MySensors: Fewer comments in const.py

This commit is contained in:
functionpointer
2021-01-27 22:21:47 +01:00
parent d67546ca6d
commit d5ecfa08f4

View File

@@ -44,23 +44,24 @@ UPDATE_DELAY: float = 0.1
SERVICE_SEND_IR_CODE: str = "send_ir_code" SERVICE_SEND_IR_CODE: str = "send_ir_code"
SensorType = str SensorType = str
"""S_DOOR, S_MOTION, S_SMOKE, ...""" # S_DOOR, S_MOTION, S_SMOKE, ...
ValueType = str ValueType = str
"""V_TRIPPED, V_ARMED, V_STATUS, V_PERCENTAGE, ...""" # V_TRIPPED, V_ARMED, V_STATUS, V_PERCENTAGE, ...
GatewayId = str GatewayId = str
"""a unique id generated by config_flow.py and stored in the ConfigEntry as the entry id. # a unique id generated by config_flow.py and stored in the ConfigEntry as the entry id.
#
# Gateway may be fetched by giving the gateway id to get_mysensors_gateway()
Gateway may be fetched by giving the gateway id to get_mysensors_gateway()
"""
DevId = Tuple[GatewayId, int, int, int] DevId = Tuple[GatewayId, int, int, int]
"""describes the backend of a hass entity. Contents are: GatewayId, node_id, child_id, v_type as int # describes the backend of a hass entity. Contents are: GatewayId, node_id, child_id, v_type as int
#
The string version of v_type can be looked up in the enum gateway.const.SetReq of the appropriate BaseAsyncGateway # The string version of v_type can be looked up in the enum gateway.const.SetReq of the appropriate BaseAsyncGateway
Home Assistant Entities are quite limited and only ever do one thing. # Home Assistant Entities are quite limited and only ever do one thing.
MySensors Nodes have multiple child_ids each with a s_type several associated v_types # MySensors Nodes have multiple child_ids each with a s_type several associated v_types
The MySensors integration brings these together by creating an entity for every v_type of every child_id of every node. # The MySensors integration brings these together by creating an entity for every v_type of every child_id of every node.
The DevId tuple perfectly captures this. # The DevId tuple perfectly captures this.
"""
BINARY_SENSOR_TYPES: Dict[SensorType, Set[ValueType]] = { BINARY_SENSOR_TYPES: Dict[SensorType, Set[ValueType]] = {
"S_DOOR": {"V_TRIPPED"}, "S_DOOR": {"V_TRIPPED"},
@@ -144,20 +145,15 @@ PLATFORM_TYPES: Dict[str, Dict[SensorType, Set[ValueType]]] = {
"sensor": SENSOR_TYPES, "sensor": SENSOR_TYPES,
"switch": SWITCH_TYPES, "switch": SWITCH_TYPES,
} }
"""dict mapping hass platform name to dict that maps mysensors s_type to set of mysensors v_type"""
FLAT_PLATFORM_TYPES: Dict[Tuple[str, SensorType], Set[ValueType]] = { FLAT_PLATFORM_TYPES: Dict[Tuple[str, SensorType], Set[ValueType]] = {
(platform, s_type_name): v_type_name (platform, s_type_name): v_type_name
for platform, platform_types in PLATFORM_TYPES.items() for platform, platform_types in PLATFORM_TYPES.items()
for s_type_name, v_type_name in platform_types.items() for s_type_name, v_type_name in platform_types.items()
} }
"""flatter version of PLATFORM_TYPES
dict mapping tuples of hass platform name and mysensors s_type to mysensors v_type
"""
TYPE_TO_PLATFORMS: Dict[SensorType, List[str]] = defaultdict(list) TYPE_TO_PLATFORMS: Dict[SensorType, List[str]] = defaultdict(list)
"""dict mapping mysensors s_type to list of hass platform name"""
for platform, platform_types in PLATFORM_TYPES.items(): for platform, platform_types in PLATFORM_TYPES.items():
for s_type_name in platform_types: for s_type_name in platform_types:
TYPE_TO_PLATFORMS[s_type_name].append(platform) TYPE_TO_PLATFORMS[s_type_name].append(platform)