mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-23 19:13:26 -06:00
This is somewhat in prep of being able to make the project file generated, but also just organizes things into more concrete directory structures.
This pulls out _all_ of the build settings from the root level, and most from the target level, into xcconfigs.
The new directory structure looks like:
- Sources
- App
- (everything from HomeAssistant/)
- WatchApp
- Shared
- MacBridge
- Extensions
- Intents
- NotificationContent
- NotificationService
- Share
- Today
- Watch
- Widgets
- Tests
- App
- UI
- Shared
Somewhat intentionally, the file structure under these is not yet standardized/organized.
The project targets are now:
- App
- WatchApp
- Shared-iOS
- Shared-watchOS
- MacBridge
- Tests-App
- Tests-UI
- Tests-Shared
- Extension-Intents
- Extension-NotificationContent
- Extension-NotificationService
- Extension-Share
- Extension-Today
- Extension-Widget
- WatchExtension-Watch
This does not yet clean up resources vs. sources, nor does it handle some of the "it's in Sources/App but it's part of Shared" crossover directory issues.
90 lines
2.8 KiB
Swift
90 lines
2.8 KiB
Swift
//
|
|
// Entity.swift
|
|
// HomeAssistant
|
|
//
|
|
// Created by Robbie Trencheny on 4/5/16.
|
|
// Copyright © 2016 Robbie Trencheny. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import CoreGraphics
|
|
import ObjectMapper
|
|
|
|
public class Entity: StaticMappable {
|
|
@objc public dynamic var ID: String = ""
|
|
@objc public dynamic var State: String = ""
|
|
@objc public dynamic var Attributes: [String: Any] {
|
|
get {
|
|
guard let dictionaryData = attributesData else {
|
|
return [String: Any]()
|
|
}
|
|
do {
|
|
let dict = try JSONSerialization.jsonObject(with: dictionaryData, options: []) as? [String: Any]
|
|
return dict!
|
|
} catch {
|
|
return [String: Any]()
|
|
}
|
|
}
|
|
|
|
set {
|
|
do {
|
|
let data = try JSONSerialization.data(withJSONObject: newValue, options: [])
|
|
attributesData = data
|
|
} catch {
|
|
attributesData = nil
|
|
}
|
|
}
|
|
}
|
|
@objc fileprivate dynamic var attributesData: Data?
|
|
@objc public dynamic var FriendlyName: String?
|
|
@objc public dynamic var Hidden = false
|
|
@objc public dynamic var Icon: String?
|
|
@objc public dynamic var MobileIcon: String?
|
|
@objc public dynamic var Picture: String?
|
|
@objc public dynamic var LastChanged: Date?
|
|
@objc public dynamic var LastUpdated: Date?
|
|
// let Groups = LinkingObjects(fromType: Group.self, property: "Entities")
|
|
|
|
// Z-Wave properties
|
|
@objc public dynamic var Location: String?
|
|
@objc public dynamic var NodeID: String?
|
|
|
|
public func mapping(map: Map) {
|
|
ID <- map["entity_id"]
|
|
State <- map["state"]
|
|
Attributes <- map["attributes"]
|
|
FriendlyName <- map["attributes.friendly_name"]
|
|
Hidden <- map["attributes.hidden"]
|
|
Icon <- map["attributes.icon"]
|
|
MobileIcon <- map["attributes.mobile_icon"]
|
|
Picture <- map["attributes.entity_picture"]
|
|
LastChanged <- (map["last_changed"], HomeAssistantTimestampTransform())
|
|
LastUpdated <- (map["last_updated"], HomeAssistantTimestampTransform())
|
|
|
|
// Z-Wave properties
|
|
NodeID <- map["attributes.node_id"]
|
|
Location <- map["attributes.location"]
|
|
}
|
|
|
|
public var Domain: String {
|
|
return self.ID.components(separatedBy: ".")[0]
|
|
}
|
|
|
|
public class func objectForMapping(map: Map) -> BaseMappable? {
|
|
guard let entityId: String = map["entity_id"].value() else {
|
|
return nil
|
|
}
|
|
|
|
let entityType = entityId.components(separatedBy: ".")[0]
|
|
switch entityType {
|
|
case "zone":
|
|
return Zone()
|
|
case "scene":
|
|
return Scene()
|
|
default:
|
|
return Entity()
|
|
}
|
|
}
|
|
}
|