|
| 1 | +"""Small data models for the documented CasaTunes REST fields.""" |
| 2 | + |
| 3 | + |
| 4 | +class CasaException(Exception): |
| 5 | + """A transport or protocol failure.""" |
| 6 | + |
| 7 | + |
| 8 | +class CasaTunesObject: |
| 9 | + """Retain one validated JSON record without any network behavior.""" |
| 10 | + |
| 11 | + def __init__(self, client, attributes): |
| 12 | + self.attributes = dict(attributes) |
| 13 | + |
| 14 | + |
| 15 | +class CasaTunesSystem(CasaTunesObject): |
| 16 | + """Read-only accessors for System data.""" |
| 17 | + |
| 18 | + @property |
| 19 | + def MACAddress(self): |
| 20 | + return self.attributes.get("MACAddress", "") |
| 21 | + |
| 22 | + @property |
| 23 | + def AppName(self): |
| 24 | + return self.attributes.get("AppName", "") |
| 25 | + |
| 26 | + @property |
| 27 | + def CasaTunesVersion(self): |
| 28 | + return self.attributes.get("CasaTunesVersion", "") |
| 29 | + |
| 30 | + @property |
| 31 | + def RESTServicesVersion(self): |
| 32 | + return self.attributes.get("RESTServicesVersion", "") |
| 33 | + |
| 34 | + |
| 35 | +class CasaTunesZone(CasaTunesObject): |
| 36 | + """Read-only accessors for Zone data.""" |
| 37 | + |
| 38 | + @property |
| 39 | + def ZoneID(self): |
| 40 | + return self.attributes.get("ZoneID", None) |
| 41 | + |
| 42 | + @property |
| 43 | + def Name(self): |
| 44 | + return self.attributes.get("Name", "") |
| 45 | + |
| 46 | + @property |
| 47 | + def Power(self): |
| 48 | + return self.attributes.get("Power", None) |
| 49 | + |
| 50 | + @property |
| 51 | + def SourceID(self): |
| 52 | + return self.attributes.get("SourceID", None) |
| 53 | + |
| 54 | + @property |
| 55 | + def Volume(self): |
| 56 | + return self.attributes.get("Volume", None) |
| 57 | + |
| 58 | + @property |
| 59 | + def Mute(self): |
| 60 | + return self.attributes.get("Mute", False) |
| 61 | + |
| 62 | + @property |
| 63 | + def Hidden(self): |
| 64 | + return self.attributes.get("Hidden", False) |
| 65 | + |
| 66 | + @property |
| 67 | + def EnabledSources(self): |
| 68 | + return self.attributes.get("EnabledSources", None) |
| 69 | + |
| 70 | + @property |
| 71 | + def FixedVolumeEnabled(self): |
| 72 | + return self.attributes.get("FixedVolumeEnabled", False) |
| 73 | + |
| 74 | + @property |
| 75 | + def VolumeControlType(self): |
| 76 | + return self.attributes.get("VolumeControlType", 1) |
| 77 | + |
| 78 | + @property |
| 79 | + def HidePowerControl(self): |
| 80 | + return self.attributes.get("HidePowerControl", False) |
| 81 | + |
| 82 | + @property |
| 83 | + def HideSourceControl(self): |
| 84 | + return self.attributes.get("HideSourceControl", False) |
| 85 | + |
| 86 | + @property |
| 87 | + def SharedRoomID(self): |
| 88 | + return self.attributes.get("SharedRoomID", 0) |
| 89 | + |
| 90 | + @property |
| 91 | + def MasterMode(self): |
| 92 | + return self.attributes.get("MasterMode", False) |
| 93 | + |
| 94 | + @property |
| 95 | + def SleepEnabled(self): |
| 96 | + return self.attributes.get("SleepEnabled", False) |
| 97 | + |
| 98 | + @property |
| 99 | + def DND(self): |
| 100 | + return self.attributes.get("DND", False) |
| 101 | + |
| 102 | + |
| 103 | +class CasaTunesSource(CasaTunesObject): |
| 104 | + """Read-only accessors for Source data.""" |
| 105 | + |
| 106 | + @property |
| 107 | + def SourceID(self): |
| 108 | + return self.attributes.get("SourceID", None) |
| 109 | + |
| 110 | + @property |
| 111 | + def Name(self): |
| 112 | + return self.attributes.get("Name", "") |
| 113 | + |
| 114 | + @property |
| 115 | + def Hidden(self): |
| 116 | + return self.attributes.get("Hidden", False) |
| 117 | + |
| 118 | + @property |
| 119 | + def MediaTypesSupported(self): |
| 120 | + return self.attributes.get("MediaTypesSupported", 0) |
| 121 | + |
| 122 | + @property |
| 123 | + def Type(self): |
| 124 | + return self.attributes.get("Type", None) |
| 125 | + |
| 126 | + |
| 127 | +class CasaTunesNowPlaying(CasaTunesObject): |
| 128 | + """Read-only accessors for NowPlaying data.""" |
| 129 | + |
| 130 | + @property |
| 131 | + def SourceID(self): |
| 132 | + return self.attributes.get("SourceID", None) |
| 133 | + |
| 134 | + @property |
| 135 | + def Status(self): |
| 136 | + return self.attributes.get("Status", 0) |
| 137 | + |
| 138 | + @property |
| 139 | + def ShuffleMode(self): |
| 140 | + return self.attributes.get("ShuffleMode", False) |
| 141 | + |
| 142 | + @property |
| 143 | + def RepeatMode(self): |
| 144 | + return self.attributes.get("RepeatMode", 0) |
| 145 | + |
| 146 | + @property |
| 147 | + def CurrProgress(self): |
| 148 | + return self.attributes.get("CurrProgress", None) |
| 149 | + |
| 150 | + @property |
| 151 | + def CurrSong(self): |
| 152 | + return CasaTunesSong(None, self.attributes.get("CurrSong") or {}) |
| 153 | + |
| 154 | + |
| 155 | +class CasaTunesSong(CasaTunesObject): |
| 156 | + """Read-only accessors for Song data.""" |
| 157 | + |
| 158 | + @property |
| 159 | + def Title(self): |
| 160 | + return self.attributes.get("Title", "") |
| 161 | + |
| 162 | + @property |
| 163 | + def Artists(self): |
| 164 | + return self.attributes.get("Artists", "") |
| 165 | + |
| 166 | + @property |
| 167 | + def Album(self): |
| 168 | + return self.attributes.get("Album", "") |
| 169 | + |
| 170 | + @property |
| 171 | + def Duration(self): |
| 172 | + return self.attributes.get("Duration", None) |
| 173 | + |
| 174 | + @property |
| 175 | + def ArtworkURI(self): |
| 176 | + return self.attributes.get("ArtworkURI", "") |
0 commit comments