@callback
def _async_write_ha_state(self) -> None:
    'Write the state to the state machine.'
    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 {})
    if (not self.available):
        state = STATE_UNAVAILABLE
    else:
        sstate = self.state
        state = (STATE_UNKNOWN if (sstate is None) else str(sstate))
        attr.update((self.state_attributes or {}))
        extra_state_attributes = self.extra_state_attributes
        if (extra_state_attributes is None):
            extra_state_attributes = self.device_state_attributes
        attr.update((extra_state_attributes or {}))
    unit_of_measurement = self.unit_of_measurement
    if (unit_of_measurement is not None):
        attr[ATTR_UNIT_OF_MEASUREMENT] = unit_of_measurement
    entry = self.registry_entry
    name = ((entry and entry.name) or self.name)
    if (name is not None):
        attr[ATTR_FRIENDLY_NAME] = name
    icon = ((entry and entry.icon) or self.icon)
    if (icon is not None):
        attr[ATTR_ICON] = icon
    entity_picture = self.entity_picture
    if (entity_picture is not None):
        attr[ATTR_ENTITY_PICTURE] = entity_picture
    assumed_state = self.assumed_state
    if assumed_state:
        attr[ATTR_ASSUMED_STATE] = assumed_state
    supported_features = self.supported_features
    if (supported_features is not None):
        attr[ATTR_SUPPORTED_FEATURES] = supported_features
    device_class = self.device_class
    if (device_class is not None):
        attr[ATTR_DEVICE_CLASS] = str(device_class)
    end = timer()
    if (((end - start) > 0.4) and (not self._slow_reported)):
        self._slow_reported = True
        extra = ''
        if ('custom_components' in type(self).__module__):
            extra = 'Please report it to the custom component author.'
        else:
            extra = 'Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue'
            if self.platform:
                extra += f'+label%3A%22integration%3A+{self.platform.platform_name}%22'
        _LOGGER.warning('Updating state for %s (%s) took %.3f seconds. %s', self.entity_id, type(self), (end - start), extra)
    if (DATA_CUSTOMIZE in self.hass.data):
        attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
    try:
        unit_of_measure = attr.get(ATTR_UNIT_OF_MEASUREMENT)
        units = self.hass.config.units
        if ((unit_of_measure in (TEMP_CELSIUS, TEMP_FAHRENHEIT)) and (unit_of_measure != units.temperature_unit)):
            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
    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.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 {})
    if (not self.available):
        state = STATE_UNAVAILABLE
    else:
        sstate = self.state
        state = (STATE_UNKNOWN if (sstate is None) else str(sstate))
        attr.update((self.state_attributes or {}))
        extra_state_attributes = self.extra_state_attributes
        if (extra_state_attributes is None):
            extra_state_attributes = self.device_state_attributes
        attr.update((extra_state_attributes or {}))
    unit_of_measurement = self.unit_of_measurement
    if (unit_of_measurement is not None):
        attr[ATTR_UNIT_OF_MEASUREMENT] = unit_of_measurement
    entry = self.registry_entry
    name = ((entry and entry.name) or self.name)
    if (name is not None):
        attr[ATTR_FRIENDLY_NAME] = name
    icon = ((entry and entry.icon) or self.icon)
    if (icon is not None):
        attr[ATTR_ICON] = icon
    entity_picture = self.entity_picture
    if (entity_picture is not None):
        attr[ATTR_ENTITY_PICTURE] = entity_picture
    assumed_state = self.assumed_state
    if assumed_state:
        attr[ATTR_ASSUMED_STATE] = assumed_state
    supported_features = self.supported_features
    if (supported_features is not None):
        attr[ATTR_SUPPORTED_FEATURES] = supported_features
    device_class = self.device_class
    if (device_class is not None):
        attr[ATTR_DEVICE_CLASS] = str(device_class)
    end = timer()
    if (((end - start) > 0.4) and (not self._slow_reported)):
        self._slow_reported = True
        extra = 
        if ('custom_components' in type(self).__module__):
            extra = 'Please report it to the custom component author.'
        else:
            extra = 'Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue'
            if self.platform:
                extra += f'+label%3A%22integration%3A+{self.platform.platform_name}%22'
        _LOGGER.warning('Updating state for %s (%s) took %.3f seconds. %s', self.entity_id, type(self), (end - start), extra)
    if (DATA_CUSTOMIZE in self.hass.data):
        attr.update(self.hass.data[DATA_CUSTOMIZE].get(self.entity_id))
    try:
        unit_of_measure = attr.get(ATTR_UNIT_OF_MEASUREMENT)
        units = self.hass.config.units
        if ((unit_of_measure in (TEMP_CELSIUS, TEMP_FAHRENHEIT)) and (unit_of_measure != units.temperature_unit)):
            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
    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)