def __init__(self, hass, device_id, friendly_name, unit_of_measurement,
                 state_template):
        self.hass = hass
        self.entity_id = generate_entity_id(ENTITY_ID_FORMAT, device_id,
                                            hass=hass)
        self._name = friendly_name
        self._unit_of_measurement = unit_of_measurement
        self._template = state_template
        self._state = None

        self.update()

        def template_sensor_event_listener(event):
            """Called when the target device changes state."""
            self.update_ha_state(True)

        hass.bus.listen(EVENT_STATE_CHANGED, template_sensor_event_listener)
Reorders (priority, value) tuples -> priority ordered values.
dataset/ETHPy150Open home-assistant/home-assistant/homeassistant/components/sensor/template.py/SensorTemplate.__init__--crossover with--dataset/ETHPy150Open openstack/taskflow/taskflow/jobs/base.py/JobPriority.reorder