@callback
def _async_write_ha_state(self) -> None:
    'Write the state to the state machine.'
    if (self._platform_state == EntityPlatformState.REMOVED):
        return
    if (self.registry_entry and self.registry_entry.disabled_by):
        if (not self._disabled_reported):
            self._disabled_reported = True
            assert (self.platform is not None)
            _LOGGER.warning('Entity %s is incorrectly being triggered for updates while it is disabled. This is a bug in the %s integration', self.entity_id, self.platform.platform_name)
        return
    start = timer()
    attr = self.capability_attributes
    attr = (dict(attr) if attr else {})
    available = self.available
    state = self._stringify_state(available)
    if available:
        attr.update((self.state_attributes or {}))
        attr.update((self.extra_state_attributes or {}))
    if ((unit_of_measurement := self.unit_of_measurement) is not None):
        attr[ATTR_UNIT_OF_MEASUREMENT] = unit_of_measurement
    entry = self.registry_entry
    if (assumed_state := self.assumed_state):
        attr[ATTR_ASSUMED_STATE] = assumed_state
    if ((attribution := self.attribution) is not None):
        attr[ATTR_ATTRIBUTION] = attribution
    if ((device_class := ((entry and entry.device_class) or self.device_class)) is not None):
        attr[ATTR_DEVICE_CLASS] = str(device_class)
    if ((entity_picture := self.entity_picture) is not None):
        attr[ATTR_ENTITY_PICTURE] = entity_picture
    if ((icon := ((entry and entry.icon) or self.icon)) is not None):
        attr[ATTR_ICON] = icon
    if ((name := ((entry and entry.name) or self.name)) is not None):
        attr[ATTR_FRIENDLY_NAME] = name
    if ((supported_features := self.supported_features) is not None):
        attr[ATTR_SUPPORTED_FEATURES] = supported_features
    end = timer()
    if (((end - start) > 0.4) and (not self._slow_reported)):
        self._slow_reported = True
        report_issue = self._suggest_report_issue()
        _LOGGER.warning('Updating state for %s (%s) took %.3f seconds. Please %s', self.entity_id, type(self), (end - start), report_issue)
    if (DATA_CUSTOMIZE in self.hass.data):
        attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))

    def _convert_temperature(state: str, attr: dict) -> str:
        from homeassistant.components.sensor import SensorEntity
        unit_of_measure = attr.get(ATTR_UNIT_OF_MEASUREMENT)
        units = self.hass.config.units
        if ((unit_of_measure == units.temperature_unit) or (unit_of_measure not in (TEMP_CELSIUS, TEMP_FAHRENHEIT))):
            return state
        domain = split_entity_id(self.entity_id)[0]
        if (domain != 'sensor'):
            if (not self._temperature_reported):
                self._temperature_reported = True
                report_issue = self._suggest_report_issue()
                _LOGGER.warning('Entity %s (%s) relies on automatic temperature conversion, this will be unsupported in Home Assistant Core 2022.7. Please %s', self.entity_id, type(self), report_issue)
        elif (not isinstance(self, SensorEntity)):
            if (not self._temperature_reported):
                self._temperature_reported = True
                report_issue = self._suggest_report_issue()
                _LOGGER.warning('Temperature sensor %s (%s) does not inherit SensorEntity, this will be unsupported in Home Assistant Core 2022.7.Please %s', self.entity_id, type(self), report_issue)
        else:
            return state
        try:
            prec = (((len(state) - state.index('.')) - 1) if ('.' in state) else 0)
            temp = units.temperature(float(state), unit_of_measure)
            state = str((round(temp) if (prec == 0) else round(temp, prec)))
            attr[ATTR_UNIT_OF_MEASUREMENT] = units.temperature_unit
        except ValueError:
            pass
        return state
    state = _convert_temperature(state, attr)
    if ((self._context_set is not None) and ((dt_util.utcnow() - self._context_set) > self.context_recent_time)):
        self._context = None
        self._context_set = None
    self.hass.states.async_set(self.entity_id, state, attr, self.force_update, self._context)
Write the state to the state machine.
@callback
def _async_write_ha_state(self) -> None:
    
    if (self._platform_state == EntityPlatformState.REMOVED):
        return
    if (self.registry_entry and self.registry_entry.disabled_by):
        if (not self._disabled_reported):
            self._disabled_reported = True
            assert (self.platform is not None)
            _LOGGER.warning('Entity %s is incorrectly being triggered for updates while it is disabled. This is a bug in the %s integration', self.entity_id, self.platform.platform_name)
        return
    start = timer()
    attr = self.capability_attributes
    attr = (dict(attr) if attr else {})
    available = self.available
    state = self._stringify_state(available)
    if available:
        attr.update((self.state_attributes or {}))
        attr.update((self.extra_state_attributes or {}))
    if ((unit_of_measurement := self.unit_of_measurement) is not None):
        attr[ATTR_UNIT_OF_MEASUREMENT] = unit_of_measurement
    entry = self.registry_entry
    if (assumed_state := self.assumed_state):
        attr[ATTR_ASSUMED_STATE] = assumed_state
    if ((attribution := self.attribution) is not None):
        attr[ATTR_ATTRIBUTION] = attribution
    if ((device_class := ((entry and entry.device_class) or self.device_class)) is not None):
        attr[ATTR_DEVICE_CLASS] = str(device_class)
    if ((entity_picture := self.entity_picture) is not None):
        attr[ATTR_ENTITY_PICTURE] = entity_picture
    if ((icon := ((entry and entry.icon) or self.icon)) is not None):
        attr[ATTR_ICON] = icon
    if ((name := ((entry and entry.name) or self.name)) is not None):
        attr[ATTR_FRIENDLY_NAME] = name
    if ((supported_features := self.supported_features) is not None):
        attr[ATTR_SUPPORTED_FEATURES] = supported_features
    end = timer()
    if (((end - start) > 0.4) and (not self._slow_reported)):
        self._slow_reported = True
        report_issue = self._suggest_report_issue()
        _LOGGER.warning('Updating state for %s (%s) took %.3f seconds. Please %s', self.entity_id, type(self), (end - start), report_issue)
    if (DATA_CUSTOMIZE in self.hass.data):
        attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))

    def _convert_temperature(state: str, attr: dict) -> str:
        from homeassistant.components.sensor import SensorEntity
        unit_of_measure = attr.get(ATTR_UNIT_OF_MEASUREMENT)
        units = self.hass.config.units
        if ((unit_of_measure == units.temperature_unit) or (unit_of_measure not in (TEMP_CELSIUS, TEMP_FAHRENHEIT))):
            return state
        domain = split_entity_id(self.entity_id)[0]
        if (domain != 'sensor'):
            if (not self._temperature_reported):
                self._temperature_reported = True
                report_issue = self._suggest_report_issue()
                _LOGGER.warning('Entity %s (%s) relies on automatic temperature conversion, this will be unsupported in Home Assistant Core 2022.7. Please %s', self.entity_id, type(self), report_issue)
        elif (not isinstance(self, SensorEntity)):
            if (not self._temperature_reported):
                self._temperature_reported = True
                report_issue = self._suggest_report_issue()
                _LOGGER.warning('Temperature sensor %s (%s) does not inherit SensorEntity, this will be unsupported in Home Assistant Core 2022.7.Please %s', self.entity_id, type(self), report_issue)
        else:
            return state
        try:
            prec = (((len(state) - state.index('.')) - 1) if ('.' in state) else 0)
            temp = units.temperature(float(state), unit_of_measure)
            state = str((round(temp) if (prec == 0) else round(temp, prec)))
            attr[ATTR_UNIT_OF_MEASUREMENT] = units.temperature_unit
        except ValueError:
            pass
        return state
    state = _convert_temperature(state, attr)
    if ((self._context_set is not None) and ((dt_util.utcnow() - self._context_set) > self.context_recent_time)):
        self._context = None
        self._context_set = None
    self.hass.states.async_set(self.entity_id, state, attr, self.force_update, self._context)