def make_simple_thermostat(interface_id, address): """ Helper to create SimpleThermostat entities. """ unique_id = generate_unique_id(address) entity_id = "climate.{}".format(unique_id) if entity_id in data.ENTITIES: LOG.debug("make_simple_thermostat: Skipping %s (already exists)", entity_id) device_entities = { ENTITY_ACTUAL_TEMPERATURE: f"sensor.{unique_id}_1_temperature", ENTITY_HUMIDITY: f"sensor.{unique_id}_1_humidity", ENTITY_SET_TEMPERATURE: f"number.{unique_id}_2_setpoint", } data.ENTITIES[entity_id] = SimpleThermostat(interface_id, address, entity_id, unique_id, device_entities) data.HA_DEVICES[address].entities.add(entity_id) return [entity_id]
def make_ip_thermostat(interface_id, address): """ Helper to create IPThermostat entities. We use a helper-function to avoid raising exceptions during object-init. """ unique_id = generate_unique_id(address) entity_id = "climate.{}".format(unique_id) if entity_id in data.ENTITIES: LOG.debug("make_ip_thermostat: Skipping %s (already exists)", entity_id) device_entities = { ENTITY_ACTUAL_TEMPERATURE: f"sensor.{unique_id}_1_actual_temperature", ENTITY_SET_TEMPERATURE: f"number.{unique_id}_1_set_point_temperature", ENTITY_CONTROL_MODE: f"number.{unique_id}_1_control_mode", ENTITY_SET_POINT_MODE: f"number.{unique_id}_1_set_point_mode", ENTITY_BOOST_MODE: f"switch.{unique_id}_1_boost_mode", ENTITY_AWAY_MODE: f"binary_sensor.{unique_id}_1_party_mode", } data.ENTITIES[entity_id] = IPThermostat(interface_id, address, entity_id, unique_id, device_entities) data.HA_DEVICES[address].entities.add(entity_id) return [entity_id]
def make_group_thermostat(interface_id, address): """ Helper to create Thermostat entities for heating groups. We use a helper-function to avoid raising exceptions during object-init. """ unique_id = generate_unique_id(address) entity_id = "climate.{}".format(unique_id) if entity_id in data.ENTITIES: LOG.debug("make_group_thermostat: Skipping %s (already exists)", entity_id) device_entities = { ENTITY_ACTUAL_TEMPERATURE: f"sensor.{unique_id}_1_actual_temperature", ENTITY_SET_TEMPERATURE: f"number.{unique_id}_1_set_temperature", ENTITY_CONTROL_MODE: f"sensor.{unique_id}_1_control_mode", ENTITY_AUTO_MODE: f"switch.{unique_id}_1_auto_mode", ENTITY_MANU_MODE: f"number.{unique_id}_1_manu_mode", ENTITY_BOOST_MODE: f"switch.{unique_id}_1_boost_mode", ENTITY_COMFORT_MODE: f"switch.{unique_id}_1_comfort_mode", ENTITY_LOWERING_MODE: f"switch.{unique_id}_1_lowering_mode", } data.ENTITIES[entity_id] = Thermostat(interface_id, address, entity_id, unique_id, device_entities) data.HA_DEVICES[address].entities.add(entity_id) return [entity_id]
def create_entity(address, parameter, parameter_data, interface_id): """ Helper that looks at the paramsets, decides which default platform should be used, and creates the required entities. """ if parameter in IGNORED_PARAMETERS: LOG.debug("create_entity: Ignoring parameter: %s (%s)", parameter, address) return None if (address, parameter) not in hahomematic.data.EVENT_SUBSCRIPTIONS: hahomematic.data.EVENT_SUBSCRIPTIONS[(address, parameter)] = [] unique_id = generate_unique_id(address, parameter) # TODO: How do we handle existing entities? Entities should be removed when the server # receives a deleteDevices call. When the paramset has updated it should be recreated probably. LOG.debug("create_entity: Creating entity for %s, %s, %s", address, parameter, interface_id) entity_id = None if parameter_data[ATTR_HM_OPERATIONS] & OPERATION_WRITE: if parameter_data[ATTR_HM_TYPE] == TYPE_ACTION: LOG.debug("create_entity: switch (action): %s %s", address, parameter) entity_id = f"switch.{unique_id}" if entity_id in hahomematic.data.ENTITIES: LOG.debug("create_entity: Skipping %s (already exists)", entity_id) return None hahomematic.data.ENTITIES[entity_id] = switch( interface_id, unique_id, address, parameter, parameter_data ) else: if parameter_data[ATTR_HM_TYPE] == TYPE_BOOL: LOG.debug("create_entity: switch: %s %s", address, parameter) entity_id = f"switch.{unique_id}" if entity_id in hahomematic.data.ENTITIES: LOG.debug("create_entity: Skipping %s (already exists)", entity_id) return None hahomematic.data.ENTITIES[entity_id] = switch( interface_id, unique_id, address, parameter, parameter_data ) elif parameter_data[ATTR_HM_TYPE] == TYPE_ENUM: LOG.debug("create_entity: input_select: %s %s", address, parameter) entity_id = f"input_select.{unique_id}" if entity_id in hahomematic.data.ENTITIES: LOG.debug("create_entity: Skipping %s (already exists)", entity_id) return None hahomematic.data.ENTITIES[entity_id] = input_select( interface_id, unique_id, address, parameter, parameter_data ) elif parameter_data[ATTR_HM_TYPE] in [TYPE_FLOAT, TYPE_INTEGER]: LOG.debug("create_entity: number: %s %s", address, parameter) entity_id = f"number.{unique_id}" if entity_id in hahomematic.data.ENTITIES: LOG.debug("create_entity: Skipping %s (already exists)", entity_id) return None hahomematic.data.ENTITIES[entity_id] = number( interface_id, unique_id, address, parameter, parameter_data ) elif parameter_data[ATTR_HM_TYPE] == TYPE_STRING: LOG.debug("create_entity: input_text: %s %s", address, parameter) entity_id = f"input_text.{unique_id}" if entity_id in hahomematic.data.ENTITIES: LOG.debug("create_entity: Skipping %s (already exists)", entity_id) return None hahomematic.data.ENTITIES[entity_id] = input_text( interface_id, unique_id, address, parameter, parameter_data ) else: LOG.warning("unsupported actor: %s %s %s", address, parameter, parameter_data[ATTR_HM_TYPE]) else: if parameter_data[ATTR_HM_TYPE] == TYPE_BOOL: LOG.debug("create_entity: binary_sensor: %s %s", address, parameter) entity_id = f"binary_sensor.{unique_id}" if entity_id in hahomematic.data.ENTITIES: LOG.debug("create_entity: Skipping %s (already exists)", entity_id) return None hahomematic.data.ENTITIES[entity_id] = binary_sensor( interface_id, unique_id, address, parameter, parameter_data ) else: LOG.debug("create_entity: sensor: %s %s", address, parameter) entity_id = f"sensor.{unique_id}" if entity_id in hahomematic.data.ENTITIES: LOG.debug("create_entity: Skipping %s (already exists)", entity_id) return None hahomematic.data.ENTITIES[entity_id] = sensor( interface_id, unique_id, address, parameter, parameter_data ) return entity_id