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) }
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)}
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), }
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)}
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)}
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
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), }
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), }
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, }
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, }
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())
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())
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
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
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
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) }
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()))
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)))