Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Responses contain an XML serialization error... #3

Open
Tjossul opened this issue Dec 23, 2023 · 1 comment
Open

Responses contain an XML serialization error... #3

Tjossul opened this issue Dec 23, 2023 · 1 comment

Comments

@Tjossul
Copy link

Tjossul commented Dec 23, 2023

Hello,

I have a FritzBox Cable and a Fritz Dect 210 registered there. Requesting the session ID is successfull but requesting devices with GetDevices(...) or GetDeviceInfos(...) using this requested session ID gives me an XML serialization error.

    private async Task RunFritz()
    {
        try
        {
            var homeAutomationClient = new Fritz.HomeAutomation.HomeAutomationClient();

            var sessionId = await homeAutomationClient.GetSessionId("myUserName", "myPassword");

            var devices = await  homeAutomationClient.GetDevices(sessionId);

            var info = await homeAutomationClient.GetDeviceInfos(sessionId, "myFritzDectAid");
        }
        catch(Exception ex)
        {

        }
    }

Error: "Instance validation error: 'manuell' is not a valid value for SwitchMode."

If I run the request urls in the browser I get the right XML response, e.g.:

http://fritz.box/webservices/homeautoswitch.lua?sid=68986fb1a557923b&switchcmd=getdevicelistinfos

<devicelist version="1" fwversion="7.57">
<device identifier="11657 0760001" id="16" functionbitmask="35712" fwversion="04.25" manufacturer="AVM" productname="FRITZ!DECT 210">
<present>1</present>
<txbusy>0</txbusy>
<name>FRITZ!DECT 210 #1</name>
<switch>
<state>1</state>
<mode>manuell</mode>
<lock>0</lock>
<devicelock>0</devicelock>
</switch>
<simpleonoff>
<state>1</state>
</simpleonoff>
<powermeter>
<voltage>232781</voltage>
<power>0</power>
<energy>0</energy>
</powermeter>
<temperature>
<celsius>220</celsius>
<offset>0</offset>
</temperature>
</device>
<group synchronized="0" identifier="grp8FD40C-3F744C05E" id="900" functionbitmask="37504" fwversion="1.0" manufacturer="AVM" productname="">
<present>1</present>
<txbusy>0</txbusy>
<name>Solar</name>
<switch>
<state>0</state>
<mode>manuell</mode>
<lock>0</lock>
<devicelock>0</devicelock>
</switch>
<simpleonoff>
<state>0</state>
</simpleonoff>
<powermeter>
<voltage>232781</voltage>
<power>0</power>
<energy>0</energy>
</powermeter>
<groupinfo>
<masterdeviceid>0</masterdeviceid>
<members>16</members>
</groupinfo>
</group>
</devicelist>

As you can see this mode is not part of your SwitchMode enums and additionally localised as German. Maybe you cannot use mode/SwitchMode as enum?!

I do not really know what to do or what the problem is. Could you give me some advice?

Thanks.
Sebastian.

@Tjossul Tjossul changed the title Responses contain no usable data... Responses contain an XML serialization error... Dec 23, 2023
@Tjossul
Copy link
Author

Tjossul commented Dec 23, 2023

Hello,

I have a solution for this:

    /// <summary>
    /// Mode of the 
    /// </summary>
    public enum SwitchMode
    {
        /// <summary>
        /// Device is off
        /// </summary>
        [XmlEnum(Name = "0")]
        Off,

        /// <summary>
        /// Device is on
        /// </summary>
        [XmlEnum(Name = "1")]
        On,

        /// <summary>
        /// Device is in auto mode
        /// </summary>
        [XmlEnum(Name = "auto")]
        Auto,

        /// <summary>
        /// Device is in manual mode
        /// </summary>
        Manual
    }
    /// <summary>
    /// Switch
    /// </summary>
    [Serializable]
    [XmlRoot(ElementName = "switch")]
    public class Switch
    {
        /// <summary>
        /// State
        /// </summary>
        [XmlElement("state")]
        public State State { get; set; }

        /// <summary>
        /// Mode state
        /// </summary>
        [XmlIgnore]
        public SwitchMode SwitchMode { get; set; }

        /// <summary>
        /// Mode state
        /// </summary>
        [XmlElement("mode")]
        public string SwitchModeParse
        {
            get { return SwitchMode.ToString(); }
            set { SwitchMode = Enum.TryParse(value, out SwitchMode enumValue) ? enumValue : SwitchMode.Manual; }
        }

        /// <summary>
        /// Lock state
        /// </summary>
        [XmlElement("lock")]
        public Lock Lock { get; set; }

        /// <summary>
        /// device lock state
        /// </summary>
        [XmlElement("devicelock")]
        public Lock DeviceLock { get; set; }
    }

This works for me.

Regards.
Sebastian.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant