Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
safetcut-app
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
atichat
safetcut-app
Commits
8181b820
Commit
8181b820
authored
Sep 13, 2019
by
Tonk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update switch on/off subbreaker
parent
bf95de6e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
14 deletions
+81
-14
components/MeterCard.js
+10
-5
reduxStore/actions/currentSelectedAction.js
+43
-7
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
+28
-2
No files found.
components/MeterCard.js
View file @
8181b820
...
...
@@ -14,16 +14,16 @@ class MeterCard extends Component {
const
deviceId
=
this
.
props
.
item
.
deviceId
;
await
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
};
componentDidMount
=
async
()
=>
{
await
this
.
getShadow
();
componentDidMount
=
()
=>
{
this
.
getShadow
();
console
.
log
(
'meter props'
,
this
.
props
);
};
componentDidUpdate
=
async
(
prevProps
,
prevState
)
=>
{
componentDidUpdate
=
(
prevProps
,
prevState
)
=>
{
if
(
prevProps
.
shadow
!==
this
.
props
.
shadow
)
{
await
this
.
setInitState
();
this
.
setInitState
();
}
};
setInitState
=
async
()
=>
{
setInitState
=
()
=>
{
const
{
shadow
}
=
this
.
props
;
this
.
setState
({
isPowerOn
:
shadow
.
SM1
.
BK_S
,
...
...
@@ -73,6 +73,11 @@ class MeterCard extends Component {
<
/View
>
<
/Row
>
<
/View
>
<
View
style
=
{[
theme
.
rowContainer
,
{
position
:
'absolute'
,
top
:
10
,
right
:
5
}]}
>
<
Icon
name
=
"wifi"
type
=
"FontAwesome"
style
=
{
styles
.
iconStyle
}
/
>
<
Icon
name
=
{
item
.
isSharing
?
'users'
:
'user'
}
type
=
"FontAwesome"
style
=
{
styles
.
iconStyle
}
/
>
<
View
style
=
{[
styles
.
online
,
{
backgroundColor
:
item
.
isOnline
?
'#10ca88'
:
color
.
primary
}]}
/
>
<
/View
>
<
/BaseButton
>
)
:
(
<
TouchableOpacity
onPress
=
{
this
.
props
.
onPressEachCard
}
style
=
{
styles
.
cardContainer
}
>
...
...
reduxStore/actions/currentSelectedAction.js
View file @
8181b820
...
...
@@ -121,13 +121,6 @@ export const setMainStatus = value => async (dispatch, getState) => {
};
const
data
=
{
data
:
{
CMD_MSG
:
{
MSG1
:
command
()
}
}
};
// console.log('value', value, 'command', command(), 'qs', qs.stringify({ data: { CMD_MSG: { MSG1: command() } } }));
// console.log('selectedDeviceId', selectedDeviceId);
// console.log(idToken);
// console.log(URL);
// console.log(data);
// console.log(JSON.stringify(data).replace(/\"/g, ''));
const
options
=
{
method
:
'PUT'
,
headers
:
{
Authorization
:
`Token
${
idToken
}
`
,
'content-Type'
:
'text/plain'
},
...
...
@@ -154,6 +147,49 @@ export const setMainStatus = value => async (dispatch, getState) => {
}
};
export
const
setSubBreakerStatus
=
(
value
,
MainIndex
,
SubIndex
)
=>
async
(
dispatch
,
getState
)
=>
{
const
{
currentSelectedDeviceReducer
}
=
getState
();
const
{
currentSelectedData
,
shadow
}
=
currentSelectedDeviceReducer
;
const
selectedDeviceId
=
currentSelectedData
.
deviceId
;
const
URL
=
`
${
baseURL
}
/shadow/
${
selectedDeviceId
}
`
;
const
idToken
=
await
app
.
auth
().
currentUser
.
getIdToken
(
true
);
const
command
=
()
=>
{
switch
(
value
)
{
case
true
:
return
`L
${
MainIndex
+
1
}
B
${
SubIndex
+
1
}
_ON`
;
case
false
:
return
`L
${
MainIndex
+
1
}
B
${
SubIndex
+
1
}
_OFF`
;
}
};
const
data
=
{
data
:
{
CMD_MSG
:
{
MSG1
:
command
()
}
}
};
const
options
=
{
method
:
'PUT'
,
headers
:
{
Authorization
:
`Token
${
idToken
}
`
,
'content-Type'
:
'text/plain'
},
url
:
URL
,
data
:
JSON
.
stringify
(
data
).
replace
(
/
\"
/g
,
''
),
};
try
{
const
{
data
:
{
writeShadow
:
{
value
:
{
CMD_MSG
},
},
},
}
=
await
axios
(
options
);
// console.log(value);
// console.log('ori', shadow);
// const newShadow = { ...shadow, CMD_MSG, SM1: { ...shadow.SM1, BK_S: value ? 1 : 0 } };
// console.log('new', newShadow);
// dispatch(getCurrentSelectedShadowAction(newShadow));
}
catch
(
error
)
{
console
.
log
(
error
);
}
};
// export const getCurrentSelectedData = (deviceId, mcbLinkId, subBreakerId) => (dispatch, getState) => {
// const { currentSelectedDeviceReducer } = getState();
// const { selectedDeviceId } = currentSelectedDeviceReducer;
...
...
screens/Private/SmartMeterScreen/SmartMeterDetailScreen.js
View file @
8181b820
...
...
@@ -9,6 +9,7 @@ import {
getCurrentSelectedShadow
,
loadingAction
,
setMainStatus
,
setSubBreakerStatus
,
}
from
'../../../reduxStore/actions/currentSelectedAction'
;
import
{
getTimers
,
loadingTimersAction
}
from
'../../../reduxStore/actions/timersAction'
;
import
{
isIphoneX
}
from
'../../../utils/isPhoneX'
;
...
...
@@ -219,12 +220,32 @@ class SmartMeterDetailScreen extends Component {
this
.
setState
(
prevState
=>
(
mcbLink
.
isExpand
=
!
prevState
.
mcbLinksInfo
[
indexMcbLinks
].
isExpand
));
const
renderSubBreaker
=
(
subBreaker
,
indexSubBreakers
)
=>
{
const
handleOnPressSubBreakerSwitch
=
()
=>
const
handleOnPressSubBreakerSwitch
=
async
value
=>
{
this
.
setState
(
prevState
=>
(
subBreaker
.
isPowerOn
=
!
prevState
.
subBreakersInfo
[
indexMcbLinks
][
indexSubBreakers
].
isPowerOn
)
);
const
deviceId
=
this
.
props
.
navigation
.
getParam
(
'deviceId'
);
await
this
.
props
.
setSubBreakerStatus
(
value
,
indexMcbLinks
,
indexSubBreakers
);
let
test
=
setInterval
(()
=>
{
this
.
props
.
getCurrentSelectedShadow
(
deviceId
);
console
.
log
(
'getShadow'
);
},
2000
);
if
(
this
.
state
.
prevShadow
!==
props
.
shadow
)
{
clearInterval
(
test
);
return
{
isWaiting
:
false
};
}
else
{
setTimeout
(()
=>
{
clearInterval
(
test
);
},
6000
);
}
};
const
isSubOn
=
this
.
props
.
shadow
[
`ML
${
indexMcbLinks
+
1
}
`
][
`L
${
indexMcbLinks
+
1
}
B
${
indexSubBreakers
+
1
}
`
];
return
(
<
View
style
=
{{
...
...
@@ -250,7 +271,11 @@ class SmartMeterDetailScreen extends Component {
<
/View
>
<
/Left
>
<
Right
>
<
Switch
value
=
{
subBreaker
.
isPowerOn
}
onChange
=
{
handleOnPressSubBreakerSwitch
}
/
>
<
Switch
disabled
=
{
this
.
props
.
shadow
.
SM1
.
BK_S
===
0
?
true
:
false
}
value
=
{
isSubOn
===
1
?
true
:
false
}
onValueChange
=
{
value
=>
handleOnPressSubBreakerSwitch
(
value
)}
/
>
<
/Right
>
<
/Row
>
<
/View
>
...
...
@@ -374,6 +399,7 @@ const mapDispatchToProps = {
loadingTimersAction
,
getTimers
,
setMainStatus
,
setSubBreakerStatus
,
};
const
withNavSmartMeterDetailScreen
=
withNavigationFocus
(
SmartMeterDetailScreen
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment