'Initialize the HistoryStats sensor.'

def __init__(self, hass, entity_id, entity_state, start, end, duration, sensor_type, name):

    self._hass = hass
    self._entity_id = entity_id
    self._entity_state = entity_state
    self._duration = duration
    self._start = start
    self._end = end
    self._type = sensor_type
    self._name = name
    self._unit_of_measurement = UNITS[sensor_type]
    self._period = (datetime.datetime.now(), datetime.datetime.now())
    self.value = 0
    self.count = 0
    def force_refresh(*args):
        'Force    the    component    to    refresh.'
        self.schedule_update_ha_state(True)
    hass.bus.listen_once(EVENT_HOMEASSISTANT_START, force_refresh)
    track_state_change(hass, entity_id, force_refresh)
