Beispiel #1
0
 def speed_count(self) -> int:
     """Return the number of speeds the fan supports."""
     return int_states_in_range(SPEED_RANGE)
Beispiel #2
0
    def _setup_from_config(self, config):
        """(Re)Setup the entity."""
        self._speed_range = (
            config.get(CONF_SPEED_RANGE_MIN),
            config.get(CONF_SPEED_RANGE_MAX),
        )
        self._topic = {
            key: config.get(key)
            for key in (
                CONF_STATE_TOPIC,
                CONF_COMMAND_TOPIC,
                CONF_PERCENTAGE_STATE_TOPIC,
                CONF_PERCENTAGE_COMMAND_TOPIC,
                CONF_PRESET_MODE_STATE_TOPIC,
                CONF_PRESET_MODE_COMMAND_TOPIC,
                CONF_OSCILLATION_STATE_TOPIC,
                CONF_OSCILLATION_COMMAND_TOPIC,
            )
        }
        self._value_templates = {
            CONF_STATE: config.get(CONF_STATE_VALUE_TEMPLATE),
            ATTR_PERCENTAGE: config.get(CONF_PERCENTAGE_VALUE_TEMPLATE),
            ATTR_PRESET_MODE: config.get(CONF_PRESET_MODE_VALUE_TEMPLATE),
            ATTR_OSCILLATING: config.get(CONF_OSCILLATION_VALUE_TEMPLATE),
        }
        self._command_templates = {
            CONF_STATE: config.get(CONF_COMMAND_TEMPLATE),
            ATTR_PERCENTAGE: config.get(CONF_PERCENTAGE_COMMAND_TEMPLATE),
            ATTR_PRESET_MODE: config.get(CONF_PRESET_MODE_COMMAND_TEMPLATE),
            ATTR_OSCILLATING: config.get(CONF_OSCILLATION_COMMAND_TEMPLATE),
        }
        self._payload = {
            "STATE_ON": config[CONF_PAYLOAD_ON],
            "STATE_OFF": config[CONF_PAYLOAD_OFF],
            "OSCILLATE_ON_PAYLOAD": config[CONF_PAYLOAD_OSCILLATION_ON],
            "OSCILLATE_OFF_PAYLOAD": config[CONF_PAYLOAD_OSCILLATION_OFF],
            "PERCENTAGE_RESET": config[CONF_PAYLOAD_RESET_PERCENTAGE],
            "PRESET_MODE_RESET": config[CONF_PAYLOAD_RESET_PRESET_MODE],
        }

        self._feature_percentage = CONF_PERCENTAGE_COMMAND_TOPIC in config
        self._feature_preset_mode = CONF_PRESET_MODE_COMMAND_TOPIC in config
        if self._feature_preset_mode:
            self._preset_modes = config[CONF_PRESET_MODES_LIST]
        else:
            self._preset_modes = []

        self._speed_count = (min(int_states_in_range(self._speed_range), 100)
                             if self._feature_percentage else 100)

        optimistic = config[CONF_OPTIMISTIC]
        self._optimistic = optimistic or self._topic[CONF_STATE_TOPIC] is None
        self._optimistic_oscillation = (
            optimistic or self._topic[CONF_OSCILLATION_STATE_TOPIC] is None)
        self._optimistic_percentage = (
            optimistic or self._topic[CONF_PERCENTAGE_STATE_TOPIC] is None)
        self._optimistic_preset_mode = (
            optimistic or self._topic[CONF_PRESET_MODE_STATE_TOPIC] is None)

        self._supported_features = 0
        self._supported_features |= (
            self._topic[CONF_OSCILLATION_COMMAND_TOPIC] is not None
            and SUPPORT_OSCILLATE)
        if self._feature_percentage:
            self._supported_features |= SUPPORT_SET_SPEED
        if self._feature_preset_mode:
            self._supported_features |= SUPPORT_PRESET_MODE

        for tpl_dict in (self._command_templates, self._value_templates):
            for key, tpl in tpl_dict.items():
                if tpl is None:
                    tpl_dict[key] = lambda value: value
                else:
                    tpl.hass = self.hass
                    tpl_dict[key] = tpl.async_render_with_possible_json_value
Beispiel #3
0
 def speed_count(self) -> int:
     """Return the number of different speeds the fan can be set to."""
     return int_states_in_range(SPEED_RANGE)
Beispiel #4
0
 def speed_count(self) -> int:
     """Return the number of speeds the fan supports."""
     return int_states_in_range(
         SPEED_RANGE[SKU_TO_BASE_DEVICE[self.device.device_type]]
     )
Beispiel #5
0
 def speed_count(self) -> int:
     """Return the number of speeds the pump supports."""
     return int_states_in_range(self._speed_range)
Beispiel #6
0
 def speed_count(self) -> int:
     """Return the number of speeds the fan supports."""
     if self._node.protocol == PROTO_INSTEON:
         return 3
     return int_states_in_range(SPEED_RANGE)
Beispiel #7
0
 def speed_count(self) -> int:
     """Return the number of speeds the fan supports."""
     if self._step_range is None:
         return super().speed_count
     return int_states_in_range(self._step_range)
Beispiel #8
0
    def _setup_from_config(self, config):
        """(Re)Setup the entity."""
        self._speed_range = (
            config.get(CONF_SPEED_RANGE_MIN),
            config.get(CONF_SPEED_RANGE_MAX),
        )
        self._topic = {
            key: config.get(key)
            for key in (
                CONF_STATE_TOPIC,
                CONF_COMMAND_TOPIC,
                CONF_PERCENTAGE_STATE_TOPIC,
                CONF_PERCENTAGE_COMMAND_TOPIC,
                CONF_PRESET_MODE_STATE_TOPIC,
                CONF_PRESET_MODE_COMMAND_TOPIC,
                CONF_SPEED_STATE_TOPIC,
                CONF_SPEED_COMMAND_TOPIC,
                CONF_OSCILLATION_STATE_TOPIC,
                CONF_OSCILLATION_COMMAND_TOPIC,
            )
        }
        self._value_templates = {
            CONF_STATE: config.get(CONF_STATE_VALUE_TEMPLATE),
            ATTR_PERCENTAGE: config.get(CONF_PERCENTAGE_VALUE_TEMPLATE),
            ATTR_PRESET_MODE: config.get(CONF_PRESET_MODE_VALUE_TEMPLATE),
            # ATTR_SPEED is deprecated in the schema, support will be removed after a quarter (2021.7)
            ATTR_SPEED: config.get(CONF_SPEED_VALUE_TEMPLATE),
            ATTR_OSCILLATING: config.get(CONF_OSCILLATION_VALUE_TEMPLATE),
        }
        self._command_templates = {
            CONF_STATE: config.get(CONF_COMMAND_TEMPLATE),
            ATTR_PERCENTAGE: config.get(CONF_PERCENTAGE_COMMAND_TEMPLATE),
            ATTR_PRESET_MODE: config.get(CONF_PRESET_MODE_COMMAND_TEMPLATE),
            ATTR_OSCILLATING: config.get(CONF_OSCILLATION_COMMAND_TEMPLATE),
        }
        self._payload = {
            "STATE_ON": config[CONF_PAYLOAD_ON],
            "STATE_OFF": config[CONF_PAYLOAD_OFF],
            "OSCILLATE_ON_PAYLOAD": config[CONF_PAYLOAD_OSCILLATION_ON],
            "OSCILLATE_OFF_PAYLOAD": config[CONF_PAYLOAD_OSCILLATION_OFF],
            # The use of legacy speeds is deprecated in the schema, support will be removed after a quarter (2021.7)
            "SPEED_LOW": config[CONF_PAYLOAD_LOW_SPEED],
            "SPEED_MEDIUM": config[CONF_PAYLOAD_MEDIUM_SPEED],
            "SPEED_HIGH": config[CONF_PAYLOAD_HIGH_SPEED],
            "SPEED_OFF": config[CONF_PAYLOAD_OFF_SPEED],
        }
        # The use of legacy speeds is deprecated in the schema, support will be removed after a quarter (2021.7)
        self._feature_legacy_speeds = not self._topic[
            CONF_SPEED_COMMAND_TOPIC] is None
        if self._feature_legacy_speeds:
            self._legacy_speeds_list = config[CONF_SPEED_LIST]
            self._legacy_speeds_list_no_off = speed_list_without_preset_modes(
                self._legacy_speeds_list)

        self._feature_percentage = CONF_PERCENTAGE_COMMAND_TOPIC in config
        self._feature_preset_mode = CONF_PRESET_MODE_COMMAND_TOPIC in config
        if self._feature_preset_mode:
            self._preset_modes = config[CONF_PRESET_MODES_LIST]
        else:
            self._preset_modes = []

        if self._feature_percentage:
            self._speed_count = min(int_states_in_range(self._speed_range),
                                    100)
        else:
            self._speed_count = len(self._legacy_speeds_list_no_off) or 100

        optimistic = config[CONF_OPTIMISTIC]
        self._optimistic = optimistic or self._topic[CONF_STATE_TOPIC] is None
        self._optimistic_oscillation = (
            optimistic or self._topic[CONF_OSCILLATION_STATE_TOPIC] is None)
        self._optimistic_percentage = (
            optimistic or self._topic[CONF_PERCENTAGE_STATE_TOPIC] is None)
        self._optimistic_preset_mode = (
            optimistic or self._topic[CONF_PRESET_MODE_STATE_TOPIC] is None)
        self._optimistic_speed = (optimistic or
                                  self._topic[CONF_SPEED_STATE_TOPIC] is None)

        self._supported_features = 0
        self._supported_features |= (
            self._topic[CONF_OSCILLATION_COMMAND_TOPIC] is not None
            and SUPPORT_OSCILLATE)
        if self._feature_percentage or self._feature_legacy_speeds:
            self._supported_features |= SUPPORT_SET_SPEED
        if self._feature_preset_mode:
            self._supported_features |= SUPPORT_PRESET_MODE

        for tpl_dict in [self._command_templates, self._value_templates]:
            for key, tpl in tpl_dict.items():
                if tpl is None:
                    tpl_dict[key] = lambda value: value
                else:
                    tpl.hass = self.hass
                    tpl_dict[key] = tpl.async_render_with_possible_json_value
Beispiel #9
0
 def speed_count(self):
     """Return the number of speeds the fan supports."""
     return int_states_in_range((self._minimum_speed, self._fan.max_speed))
Beispiel #10
0
 def speed_count(self):
     return int_states_in_range(BAYERNLUEFTER_SPEED_RANGE)
Beispiel #11
0
 def speed_count(self) -> int:
     """Speed count for the fan."""
     speed_count = int_states_in_range(self._speed_range)
     _LOGGER.debug("Fan speed_count: %s", speed_count)
     return speed_count