コード例 #1
0
ファイル: sun.py プロジェクト: yuetianle/home-assistant
 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
ファイル: sun.py プロジェクト: 100dayproject/home-assistant
 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
ファイル: core.py プロジェクト: yuetianle/home-assistant
    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
ファイル: core.py プロジェクト: Julian/home-assistant
    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
ファイル: core.py プロジェクト: rthill/home-assistant
    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
ファイル: core.py プロジェクト: Cinntax/home-assistant
    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
ファイル: vera.py プロジェクト: ycaihua/home-assistant
    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
ファイル: core.py プロジェクト: Cinntax/home-assistant
 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
ファイル: core.py プロジェクト: Julian/home-assistant
 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
ファイル: logbook.py プロジェクト: FanaHOVA/home-assistant
 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
ファイル: logbook.py プロジェクト: TangoAlpha/home-assistant
 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
ファイル: logbook.py プロジェクト: wuub/home-assistant
 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
ファイル: test_core.py プロジェクト: niedfelj/home-assistant
    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
ファイル: test_core.py プロジェクト: bradsk88/home-assistant
    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
ファイル: vera.py プロジェクト: wuub/home-assistant
    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
ファイル: vera.py プロジェクト: Joan93/home-assistant
    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
ファイル: vera.py プロジェクト: linuxssm/home-assistant
    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
ファイル: sun.py プロジェクト: ddyeakley/home-assistant
 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
ファイル: sun.py プロジェクト: cferrer101/home-assistant
 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
ファイル: test_dt.py プロジェクト: zgreatone/home-assistant
 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
ファイル: test_dt.py プロジェクト: zgreatone/home-assistant
 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)))