| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#pragma once |
| 22 |
|
| 23 |
#include <string> |
| 24 |
|
| 25 |
#include "DataModel/AccessoryBase.h" |
| 26 |
#include "DataModel/LayoutItem.h" |
| 27 |
#include "DataModel/LockableItem.h" |
| 28 |
#include "DataTypes.h" |
| 29 |
|
| 30 |
class Manager; |
| 31 |
|
| 32 |
namespace DataModel |
| 33 |
{ |
| 34 |
class Switch : public AccessoryBase, public LayoutItem, public LockableItem |
| 35 |
{ |
| 36 |
public: |
| 37 |
Switch() = delete; |
| 38 |
Switch(const Switch&) = delete; |
| 39 |
Switch& operator=(const Switch&) = delete; |
| 40 |
|
| 41 |
Switch(const SwitchID switchID) |
| 42 |
: AccessoryBase(), |
| 43 |
LayoutItem(switchID), |
| 44 |
LockableItem() |
| 45 |
{ |
| 46 |
} |
| 47 |
|
| 48 |
Switch(__attribute__((unused)) Manager* manager, const SwitchID switchID) |
| 49 |
: Switch(switchID) |
| 50 |
{ |
| 51 |
} |
| 52 |
|
| 53 |
Switch(const std::string& serialized) |
| 54 |
{ |
| 55 |
Deserialize(serialized); |
| 56 |
} |
| 57 |
|
| 58 |
ObjectType GetObjectType() const override |
| 59 |
{ |
| 60 |
return ObjectTypeSwitch; |
| 61 |
} |
| 62 |
|
| 63 |
std::string GetLayoutType() const override |
| 64 |
{ |
| 65 |
return Languages::GetText(Languages::TextSwitch); |
| 66 |
} |
| 67 |
|
| 68 |
std::string Serialize() const override; |
| 69 |
|
| 70 |
using HardwareHandle::Deserialize; |
| •71 |
void Deserialize(const std::string& serialized) override; |
| 72 |
|
| 73 |
void SetAccessoryState(const AccessoryState state); |
| 74 |
|
| •75 |
inline void SetAccessoryType(AccessoryType type) override |
| 76 |
{ |
| 77 |
AccessoryBase::SetAccessoryType(type); |
| 78 |
SetSizeFromType(); |
| 79 |
} |
| 80 |
|
| 81 |
bool UsesAddress(Address address) const; |
| 82 |
|
| 83 |
std::map<DataModel::AccessoryState,Languages::TextSelector> GetStateOptions() const; |
| 84 |
|
| 85 |
AccessoryState CalculateInvertedSwitchState(const Address address, const AccessoryState state) const; |
| 86 |
|
| 87 |
static DataModel::LayoutItem::LayoutItemSize CalculateHeightFromType(AccessoryType type); |
| 88 |
|
| 89 |
Switch& operator=(const Hardware::AccessoryCacheEntry& accessory); |
| 90 |
|
| 91 |
private: |
| 92 |
inline void SetSizeFromType() |
| 93 |
{ |
| 94 |
SetWidth(Width1); |
| 95 |
SetHeight(CalculateHeightFromType(GetAccessoryType())); |
| 96 |
} |
| 97 |
}; |
| 98 |
} |