Пример #1
0
 def state_attributes(self):
     return {
         STATE_ATTR_NEXT_RISING: dt_util.datetime_to_str(self.next_rising),
         STATE_ATTR_NEXT_SETTING:
         dt_util.datetime_to_str(self.next_setting),
         STATE_ATTR_ELEVATION: round(self.solar_elevation, 2)
     }
Пример #2
0
 def state_attributes(self):
     return {
         STATE_ATTR_NEXT_RISING:
             dt_util.datetime_to_str(self.next_rising),
         STATE_ATTR_NEXT_SETTING:
             dt_util.datetime_to_str(self.next_setting),
         STATE_ATTR_ELEVATION: round(self.solar_elevation, 2)
     }
Пример #3
0
    def as_dict(self):
        """ Converts State to a dict to be used within JSON.
        Ensures: state == State.from_dict(state.as_dict()) """

        return {'entity_id': self.entity_id,
                'state': self.state,
                'attributes': self.attributes,
                'last_changed': dt_util.datetime_to_str(self.last_changed),
                'last_updated': dt_util.datetime_to_str(self.last_updated)}
Пример #4
0
    def as_dict(self):
        """ Converts State to a dict to be used within JSON.
        Ensures: state == State.from_dict(state.as_dict()) """

        return {
            "entity_id": self.entity_id,
            "state": self.state,
            "attributes": self.attributes,
            "last_changed": date_util.datetime_to_str(self.last_changed),
            "last_updated": date_util.datetime_to_str(self.last_updated),
        }
Пример #5
0
    def as_dict(self):
        """Return a dict representation of the State.

        To be used for JSON serialization.
        Ensures: state == State.from_dict(state.as_dict())
        """
        return {'entity_id': self.entity_id,
                'state': self.state,
                'attributes': self.attributes,
                'last_changed': dt_util.datetime_to_str(self.last_changed),
                'last_updated': dt_util.datetime_to_str(self.last_updated)}
Пример #6
0
    def as_dict(self):
        """Return a dict representation of the State.

        To be used for JSON serialization.
        Ensures: state == State.from_dict(state.as_dict())
        """
        return {'entity_id': self.entity_id,
                'state': self.state,
                'attributes': dict(self.attributes),
                'last_changed': dt_util.datetime_to_str(self.last_changed),
                'last_updated': dt_util.datetime_to_str(self.last_updated)}
Пример #7
0
    def device_state_attributes(self):
        """Return the state attributes of the device."""
        attr = {}

        if self.vera_device.has_battery:
            attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'

        if self.vera_device.is_armable:
            armed = self.vera_device.is_armed
            attr[ATTR_ARMED] = 'True' if armed else 'False'

        if self.vera_device.is_trippable:
            last_tripped = self.vera_device.last_trip
            if last_tripped is not None:
                utc_time = dt_util.utc_from_timestamp(int(last_tripped))
                attr[ATTR_LAST_TRIP_TIME] = dt_util.datetime_to_str(
                    utc_time)
            else:
                attr[ATTR_LAST_TRIP_TIME] = None
            tripped = self.vera_device.is_tripped
            attr[ATTR_TRIPPED] = 'True' if tripped else 'False'

        attr['Vera Device Id'] = self.vera_device.vera_device_id

        return attr
Пример #8
0
 def as_dict(self):
     """Create a dict representation of this Event."""
     return {
         'event_type': self.event_type,
         'data': dict(self.data),
         'origin': str(self.origin),
         'time_fired': dt_util.datetime_to_str(self.time_fired),
     }
Пример #9
0
 def as_dict(self):
     """Create a dict representation of this Event."""
     return {
         'event_type': self.event_type,
         'data': dict(self.data),
         'origin': str(self.origin),
         'time_fired': dt_util.datetime_to_str(self.time_fired),
     }
Пример #10
0
 def as_dict(self):
     """ Returns a dict representation of this Event. """
     return {
         "event_type": self.event_type,
         "data": dict(self.data),
         "origin": str(self.origin),
         "time_fired": date_util.datetime_to_str(self.time_fired),
     }
Пример #11
0
 def as_dict(self):
     """ Convert Entry to a dict to be used within JSON. """
     return {
         'when': dt_util.datetime_to_str(self.when),
         'name': self.name,
         'message': self.message,
         'domain': self.domain,
         'entity_id': self.entity_id,
     }
Пример #12
0
 def as_dict(self):
     """ Convert Entry to a dict to be used within JSON. """
     return {
         "when": dt_util.datetime_to_str(self.when),
         "name": self.name,
         "message": self.message,
         "domain": self.domain,
         "entity_id": self.entity_id,
     }
Пример #13
0
 def as_dict(self):
     """ Convert Entry to a dict to be used within JSON. """
     return {
         'when': dt_util.datetime_to_str(self.when),
         'name': self.name,
         'message': self.message,
         'domain': self.domain,
         'entity_id': self.entity_id,
     }
Пример #14
0
    def test_as_dict(self):
        event_type = "some_type"
        now = dt_util.utcnow()
        data = {"some": "attr"}

        event = ha.Event(event_type, data, ha.EventOrigin.local, now)
        expected = {
            "event_type": event_type,
            "data": data,
            "origin": "LOCAL",
            "time_fired": dt_util.datetime_to_str(now),
        }
        self.assertEqual(expected, event.as_dict())
Пример #15
0
    def test_as_dict(self):
        event_type = 'some_type'
        now = dt_util.utcnow()
        data = {'some': 'attr'}

        event = ha.Event(event_type, data, ha.EventOrigin.local, now)
        expected = {
            'event_type': event_type,
            'data': data,
            'origin': 'LOCAL',
            'time_fired': dt_util.datetime_to_str(now),
        }
        self.assertEqual(expected, event.as_dict())
Пример #16
0
    def test_as_dict(self):
        event_type = 'some_type'
        now = dt_util.utcnow()
        data = {'some': 'attr'}

        event = ha.Event(event_type, data, ha.EventOrigin.local, now)
        expected = {
            'event_type': event_type,
            'data': data,
            'origin': 'LOCAL',
            'time_fired': dt_util.datetime_to_str(now),
        }
        self.assertEqual(expected, event.as_dict())
Пример #17
0
    def state_attributes(self):
        attr = super().state_attributes
        if self.vera_device.has_battery:
            attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'

        if self.vera_device.is_armable:
            armed = self.vera_device.refresh_value('Armed')
            attr[ATTR_ARMED] = 'True' if armed == '1' else 'False'

        if self.vera_device.is_trippable:
            last_tripped = self.vera_device.refresh_value('LastTrip')
            if last_tripped is not None:
                utc_time = dt_util.utc_from_timestamp(int(last_tripped))
                attr[ATTR_LAST_TRIP_TIME] = dt_util.datetime_to_str(utc_time)
            else:
                attr[ATTR_LAST_TRIP_TIME] = None
            tripped = self.vera_device.refresh_value('Tripped')
            attr[ATTR_TRIPPED] = 'True' if tripped == '1' else 'False'

        attr['Vera Device Id'] = self.vera_device.vera_device_id
        return attr
Пример #18
0
    def state_attributes(self):
        attr = {}
        if self.vera_device.has_battery:
            attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + '%'

        if self.vera_device.is_armable:
            armed = self.vera_device.refresh_value('Armed')
            attr[ATTR_ARMED] = 'True' if armed == '1' else 'False'

        if self.vera_device.is_trippable:
            last_tripped = self.vera_device.refresh_value('LastTrip')
            if last_tripped is not None:
                utc_time = dt_util.utc_from_timestamp(int(last_tripped))
                attr[ATTR_LAST_TRIP_TIME] = dt_util.datetime_to_str(
                    utc_time)
            else:
                attr[ATTR_LAST_TRIP_TIME] = None
            tripped = self.vera_device.refresh_value('Tripped')
            attr[ATTR_TRIPPED] = 'True' if tripped == '1' else 'False'

        attr['Vera Device Id'] = self.vera_device.vera_device_id
        return attr
Пример #19
0
    def state_attributes(self):
        attr = super().state_attributes

        if self.vera_device.has_battery:
            attr[ATTR_BATTERY_LEVEL] = self.vera_device.battery_level + "%"

        if self.vera_device.is_armable:
            armed = self.vera_device.refresh_value("Armed")
            attr[ATTR_ARMED] = "True" if armed == "1" else "False"

        if self.vera_device.is_trippable:
            last_tripped = self.vera_device.refresh_value("LastTrip")
            if last_tripped is not None:
                utc_time = dt_util.utc_from_timestamp(int(last_tripped))
                attr[ATTR_LAST_TRIP_TIME] = dt_util.datetime_to_str(utc_time)
            else:
                attr[ATTR_LAST_TRIP_TIME] = None
            tripped = self.vera_device.refresh_value("Tripped")
            attr[ATTR_TRIPPED] = "True" if tripped == "1" else "False"

        attr["Vera Device Id"] = self.vera_device.vera_device_id

        return attr
Пример #20
0
 def state_attributes(self):
     return {
         STATE_ATTR_NEXT_RISING: dt_util.datetime_to_str(self.next_rising),
         STATE_ATTR_NEXT_SETTING: dt_util.datetime_to_str(self.next_setting)
     }
Пример #21
0
 def state_attributes(self):
     return {
         STATE_ATTR_NEXT_RISING: dt_util.datetime_to_str(self.next_rising),
         STATE_ATTR_NEXT_SETTING: dt_util.datetime_to_str(self.next_setting)
     }
Пример #22
0
 def test_datetime_to_local_str(self):
     """Test datetime_to_local_str."""
     self.assertEqual(
         dt_util.datetime_to_str(dt_util.now()),
         dt_util.datetime_to_local_str(dt_util.utcnow()))
Пример #23
0
 def test_datetime_to_str(self):
     """Test datetime_to_str."""
     self.assertEqual(
         "12:00:00 09-07-1986",
         dt_util.datetime_to_str(datetime(1986, 7, 9, 12, 0, 0)))